Skip to content

Commit ff8a3ad

Browse files
committed
make stopper non-optional in tests
In some tests the carrier didn't need a stopper since it was already in the test scope so it would drop at the end of the test and do usual cleanup. This commit unifies stuff and still moves the stopper inside the carrier so that all the tests look alike (not having ones with Some(stopper) and ones with None).
1 parent c42b29c commit ff8a3ad

File tree

2 files changed

+82
-17
lines changed

2 files changed

+82
-17
lines changed

teos/src/carrier.rs

+80-15
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub struct Carrier {
2626
block_height: u32,
2727
#[cfg(test)]
2828
/// A stopper that stops the mock bitcoind server in tests when the [`Carrier`] is dropped.
29-
_stopper: Option<crate::test_utils::BitcoindStopper>,
29+
_stopper: crate::test_utils::BitcoindStopper,
3030
}
3131

3232
impl Carrier {
@@ -35,7 +35,7 @@ impl Carrier {
3535
bitcoin_cli: Arc<BitcoindClient>,
3636
bitcoind_reachable: Arc<(Mutex<bool>, Condvar)>,
3737
last_known_block_height: u32,
38-
#[cfg(test)] stopper: Option<crate::test_utils::BitcoindStopper>,
38+
#[cfg(test)] stopper: crate::test_utils::BitcoindStopper,
3939
) -> Self {
4040
Carrier {
4141
bitcoin_cli,
@@ -218,7 +218,12 @@ mod tests {
218218
let bitcoin_cli = Arc::new(BitcoindClient::new(bitcoind_mock.url(), Auth::None).unwrap());
219219
let start_height = START_HEIGHT as u32;
220220

221-
let mut carrier = Carrier::new(bitcoin_cli, bitcoind_reachable, start_height, None);
221+
let mut carrier = Carrier::new(
222+
bitcoin_cli,
223+
bitcoind_reachable,
224+
start_height,
225+
bitcoind_mock.stopper,
226+
);
222227

223228
// Lets add some dummy data into the cache
224229
for i in 0..10 {
@@ -242,7 +247,12 @@ mod tests {
242247
let start_height = START_HEIGHT as u32;
243248
start_server(bitcoind_mock.server);
244249

245-
let mut carrier = Carrier::new(bitcoin_cli, bitcoind_reachable, start_height, None);
250+
let mut carrier = Carrier::new(
251+
bitcoin_cli,
252+
bitcoind_reachable,
253+
start_height,
254+
bitcoind_mock.stopper,
255+
);
246256
let tx = consensus::deserialize(&Vec::from_hex(TX_HEX).unwrap()).unwrap();
247257
let r = carrier.send_transaction(&tx);
248258

@@ -260,7 +270,12 @@ mod tests {
260270
let start_height = START_HEIGHT as u32;
261271
start_server(bitcoind_mock.server);
262272

263-
let mut carrier = Carrier::new(bitcoin_cli, bitcoind_reachable, start_height, None);
273+
let mut carrier = Carrier::new(
274+
bitcoin_cli,
275+
bitcoind_reachable,
276+
start_height,
277+
bitcoind_mock.stopper,
278+
);
264279
let tx = consensus::deserialize(&Vec::from_hex(TX_HEX).unwrap()).unwrap();
265280
let r = carrier.send_transaction(&tx);
266281

@@ -280,7 +295,12 @@ mod tests {
280295
let start_height = START_HEIGHT as u32;
281296
start_server(bitcoind_mock.server);
282297

283-
let mut carrier = Carrier::new(bitcoin_cli, bitcoind_reachable, start_height, None);
298+
let mut carrier = Carrier::new(
299+
bitcoin_cli,
300+
bitcoind_reachable,
301+
start_height,
302+
bitcoind_mock.stopper,
303+
);
284304
let tx = consensus::deserialize(&Vec::from_hex(TX_HEX).unwrap()).unwrap();
285305
let r = carrier.send_transaction(&tx);
286306

@@ -302,7 +322,12 @@ mod tests {
302322
let start_height = START_HEIGHT as u32;
303323
start_server(bitcoind_mock.server);
304324

305-
let mut carrier = Carrier::new(bitcoin_cli, bitcoind_reachable, start_height, None);
325+
let mut carrier = Carrier::new(
326+
bitcoin_cli,
327+
bitcoind_reachable,
328+
start_height,
329+
bitcoind_mock.stopper,
330+
);
306331
let tx = consensus::deserialize(&Vec::from_hex(TX_HEX).unwrap()).unwrap();
307332
let r = carrier.send_transaction(&tx);
308333

@@ -325,7 +350,12 @@ mod tests {
325350
let start_height = START_HEIGHT as u32;
326351
start_server(bitcoind_mock.server);
327352

328-
let mut carrier = Carrier::new(bitcoin_cli, bitcoind_reachable, start_height, None);
353+
let mut carrier = Carrier::new(
354+
bitcoin_cli,
355+
bitcoind_reachable,
356+
start_height,
357+
bitcoind_mock.stopper,
358+
);
329359
let tx = consensus::deserialize(&Vec::from_hex(TX_HEX).unwrap()).unwrap();
330360
let r = carrier.send_transaction(&tx);
331361

@@ -344,7 +374,12 @@ mod tests {
344374
let start_height = START_HEIGHT as u32;
345375
start_server(bitcoind_mock.server);
346376

347-
let mut carrier = Carrier::new(bitcoin_cli, bitcoind_reachable, start_height, None);
377+
let mut carrier = Carrier::new(
378+
bitcoin_cli,
379+
bitcoind_reachable,
380+
start_height,
381+
bitcoind_mock.stopper,
382+
);
348383
let tx = consensus::deserialize(&Vec::from_hex(TX_HEX).unwrap()).unwrap();
349384
let r = carrier.send_transaction(&tx);
350385

@@ -364,7 +399,12 @@ mod tests {
364399
let bitcoind_reachable = Arc::new((Mutex::new(false), Condvar::new()));
365400
let bitcoin_cli = Arc::new(BitcoindClient::new(bitcoind_mock.url(), Auth::None).unwrap());
366401
let start_height = START_HEIGHT as u32;
367-
let mut carrier = Carrier::new(bitcoin_cli, bitcoind_reachable.clone(), start_height, None);
402+
let mut carrier = Carrier::new(
403+
bitcoin_cli,
404+
bitcoind_reachable.clone(),
405+
start_height,
406+
bitcoind_mock.stopper,
407+
);
368408

369409
let tx = consensus::deserialize(&Vec::from_hex(TX_HEX).unwrap()).unwrap();
370410
let delay = std::time::Duration::new(3, 0);
@@ -394,7 +434,12 @@ mod tests {
394434
let start_height = START_HEIGHT as u32;
395435
start_server(bitcoind_mock.server);
396436

397-
let carrier = Carrier::new(bitcoin_cli, bitcoind_reachable, start_height, None);
437+
let carrier = Carrier::new(
438+
bitcoin_cli,
439+
bitcoind_reachable,
440+
start_height,
441+
bitcoind_mock.stopper,
442+
);
398443
let txid = Txid::from_hex(TXID_HEX).unwrap();
399444
assert!(carrier.in_mempool(&txid));
400445
}
@@ -407,7 +452,12 @@ mod tests {
407452
let start_height = START_HEIGHT as u32;
408453
start_server(bitcoind_mock.server);
409454

410-
let carrier = Carrier::new(bitcoin_cli, bitcoind_reachable, start_height, None);
455+
let carrier = Carrier::new(
456+
bitcoin_cli,
457+
bitcoind_reachable,
458+
start_height,
459+
bitcoind_mock.stopper,
460+
);
411461
let txid = Txid::from_hex(TXID_HEX).unwrap();
412462
assert!(!carrier.in_mempool(&txid));
413463
}
@@ -422,7 +472,12 @@ mod tests {
422472
let start_height = START_HEIGHT as u32;
423473
start_server(bitcoind_mock.server);
424474

425-
let carrier = Carrier::new(bitcoin_cli, bitcoind_reachable, start_height, None);
475+
let carrier = Carrier::new(
476+
bitcoin_cli,
477+
bitcoind_reachable,
478+
start_height,
479+
bitcoind_mock.stopper,
480+
);
426481
let txid = Txid::from_hex(TXID_HEX).unwrap();
427482
assert!(!carrier.in_mempool(&txid));
428483
}
@@ -436,7 +491,12 @@ mod tests {
436491
let start_height = START_HEIGHT as u32;
437492
start_server(bitcoind_mock.server);
438493

439-
let carrier = Carrier::new(bitcoin_cli, bitcoind_reachable, start_height, None);
494+
let carrier = Carrier::new(
495+
bitcoin_cli,
496+
bitcoind_reachable,
497+
start_height,
498+
bitcoind_mock.stopper,
499+
);
440500
let txid = Txid::from_hex(TXID_HEX).unwrap();
441501
assert!(!carrier.in_mempool(&txid));
442502
}
@@ -448,7 +508,12 @@ mod tests {
448508
let bitcoind_reachable = Arc::new((Mutex::new(false), Condvar::new()));
449509
let bitcoin_cli = Arc::new(BitcoindClient::new(bitcoind_mock.url(), Auth::None).unwrap());
450510
let start_height = START_HEIGHT as u32;
451-
let carrier = Carrier::new(bitcoin_cli, bitcoind_reachable.clone(), start_height, None);
511+
let carrier = Carrier::new(
512+
bitcoin_cli,
513+
bitcoind_reachable.clone(),
514+
start_height,
515+
bitcoind_mock.stopper,
516+
);
452517

453518
let txid = Txid::from_hex(TXID_HEX).unwrap();
454519
let delay = std::time::Duration::new(3, 0);

teos/src/test_utils.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ pub(crate) fn create_carrier(query: MockedServerQuery, height: u32) -> Carrier {
388388
bitcoin_cli,
389389
bitcoind_reachable,
390390
height,
391-
Some(bitcoind_mock.stopper),
391+
bitcoind_mock.stopper,
392392
)
393393
}
394394

@@ -531,7 +531,7 @@ impl Debug for BitcoindStopper {
531531
pub(crate) struct BitcoindMock {
532532
pub url: String,
533533
pub server: Server,
534-
stopper: BitcoindStopper,
534+
pub stopper: BitcoindStopper,
535535
}
536536

537537
#[derive(Default)]

0 commit comments

Comments
 (0)