Skip to content

Commit 9f90c66

Browse files
authored
Merge pull request #2729 from input-output-hk/jpraynaud/2728-fix-flakiness-dmq-tests
fix: flakiness in DMQ integration tests in CI
2 parents c79713d + a26d829 commit 9f90c66

File tree

6 files changed

+50
-7
lines changed

6 files changed

+50
-7
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/mithril-dmq/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "mithril-dmq"
33
description = "Mechanisms to publish and consume messages of a 'Decentralized Message Queue network' through a DMQ node"
4-
version = "0.1.11"
4+
version = "0.1.12"
55
authors.workspace = true
66
documentation.workspace = true
77
edition.workspace = true

internal/mithril-dmq/src/test/double/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
55
mod consumer;
66
mod publisher;
7+
mod timestamp;
78

89
pub use consumer::*;
910
pub use publisher::*;
11+
pub use timestamp::*;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use mithril_common::StdResult;
2+
3+
use crate::model::UnixTimestampProvider;
4+
5+
/// Fake implementation of a Unix current timestamp provider. For testing purposes only.
6+
pub struct FakeUnixTimestampProvider(u64);
7+
8+
impl FakeUnixTimestampProvider {
9+
/// Creates a new `FakeUnixTimestampProvider` with the given timestamp.
10+
pub fn new(timestamp: u64) -> Self {
11+
Self(timestamp)
12+
}
13+
14+
/// Computes the maximum timestamp that can be used with the given TTL and builds a new FakeUnixTimestampProvider.
15+
///
16+
/// This is useful to create messages that are valid for the maximum possible time.
17+
pub fn max_timestamp_for_ttl(ttl: u16) -> Self {
18+
Self(u32::MAX as u64 - ttl as u64 - 1)
19+
}
20+
}
21+
22+
impl UnixTimestampProvider for FakeUnixTimestampProvider {
23+
fn current_timestamp(&self) -> StdResult<u64> {
24+
Ok(self.0)
25+
}
26+
}

internal/mithril-dmq/src/test/fake_message.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ use std::sync::Arc;
55
use mithril_cardano_node_chain::test::double::FakeChainObserver;
66
use mithril_common::{crypto_helper::TryToBytes, test::crypto_helper::KesSignerFake};
77

8-
use crate::{DmqMessage, DmqMessageBuilder, test::payload::DmqMessageTestPayload};
8+
use crate::{
9+
DmqMessage, DmqMessageBuilder,
10+
test::{double::FakeUnixTimestampProvider, payload::DmqMessageTestPayload},
11+
};
912

1013
/// Computes a fake DMQ message for testing purposes.
1114
pub async fn compute_fake_msg(bytes: &[u8], test_directory: &str) -> DmqMessage {
@@ -20,7 +23,10 @@ pub async fn compute_fake_msg(bytes: &[u8], test_directory: &str) -> DmqMessage
2023
},
2124
Arc::new(FakeChainObserver::default()),
2225
)
23-
.set_ttl(100);
26+
.set_ttl(100)
27+
.set_timestamp_provider(Arc::new(FakeUnixTimestampProvider::max_timestamp_for_ttl(
28+
100,
29+
)));
2430
let message = DmqMessageTestPayload::new(bytes);
2531
dmq_builder.build(&message.to_bytes_vec().unwrap()).await.unwrap()
2632
}

internal/mithril-dmq/tests/publisher_client_server.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ use mithril_common::{
1111
use mithril_dmq::{
1212
DmqMessage, DmqMessageBuilder, DmqPublisherClient, DmqPublisherClientPallas,
1313
DmqPublisherServer, DmqPublisherServerPallas,
14-
test::{fake_message::compute_fake_msg, payload::DmqMessageTestPayload},
14+
test::{
15+
double::FakeUnixTimestampProvider, fake_message::compute_fake_msg,
16+
payload::DmqMessageTestPayload,
17+
},
1518
};
1619

1720
#[tokio::test]
@@ -59,7 +62,10 @@ async fn dmq_publisher_client_server() {
5962
},
6063
Arc::new(FakeChainObserver::default()),
6164
)
62-
.set_ttl(100);
65+
.set_ttl(100)
66+
.set_timestamp_provider(Arc::new(
67+
FakeUnixTimestampProvider::max_timestamp_for_ttl(100),
68+
));
6369
let publisher_client = DmqPublisherClientPallas::<DmqMessageTestPayload>::new(
6470
socket_path,
6571
cardano_network,
@@ -101,7 +107,10 @@ async fn dmq_publisher_client_server() {
101107
},
102108
Arc::new(FakeChainObserver::default()),
103109
)
104-
.set_ttl(100);
110+
.set_ttl(100)
111+
.set_timestamp_provider(Arc::new(
112+
FakeUnixTimestampProvider::max_timestamp_for_ttl(100),
113+
));
105114
let publisher_client = DmqPublisherClientPallas::<DmqMessageTestPayload>::new(
106115
socket_path,
107116
cardano_network,

0 commit comments

Comments
 (0)