mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-07 00:42:42 +00:00
Improve testing slot clock to allow manipulation of time in tests (#3974)
## Issue Addressed I discovered this issue while implementing [this test](https://github.com/jimmygchen/lighthouse/blob/test-example/beacon_node/network/src/beacon_processor/tests.rs#L895), where I tried to manipulate the slot clock with: `rig.chain.slot_clock.set_current_time(duration);` however the change doesn't get reflected in the `slot_clock` in `ReprocessQueue`, and I realised `slot_clock` was cloned a few times in the code, and therefore changing the time in `rig.chain.slot_clock` doesn't have any effect in `ReprocessQueue`. I've incorporated the suggestion from the @paulhauner and @michaelsproul - wrapping the `ManualSlotClock.current_time` (`RwLock<Duration>)` in an `Arc`, and the above test now passes. Let's see if this breaks any existing tests :)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use super::SlotClock;
|
||||
use parking_lot::RwLock;
|
||||
use std::convert::TryInto;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use types::Slot;
|
||||
|
||||
@@ -10,7 +11,7 @@ pub struct ManualSlotClock {
|
||||
/// Duration from UNIX epoch to genesis.
|
||||
genesis_duration: Duration,
|
||||
/// Duration from UNIX epoch to right now.
|
||||
current_time: RwLock<Duration>,
|
||||
current_time: Arc<RwLock<Duration>>,
|
||||
/// The length of each slot.
|
||||
slot_duration: Duration,
|
||||
}
|
||||
@@ -20,7 +21,7 @@ impl Clone for ManualSlotClock {
|
||||
ManualSlotClock {
|
||||
genesis_slot: self.genesis_slot,
|
||||
genesis_duration: self.genesis_duration,
|
||||
current_time: RwLock::new(*self.current_time.read()),
|
||||
current_time: Arc::clone(&self.current_time),
|
||||
slot_duration: self.slot_duration,
|
||||
}
|
||||
}
|
||||
@@ -90,7 +91,7 @@ impl SlotClock for ManualSlotClock {
|
||||
|
||||
Self {
|
||||
genesis_slot,
|
||||
current_time: RwLock::new(genesis_duration),
|
||||
current_time: Arc::new(RwLock::new(genesis_duration)),
|
||||
genesis_duration,
|
||||
slot_duration,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user