mirror of
https://github.com/libp2p/go-libp2p-peerstore.git
synced 2025-03-27 13:30:11 +08:00
fix tests; run lookahead after initial delay.
This commit is contained in:
parent
5d5a55baa5
commit
86f1626c51
@ -107,6 +107,7 @@ func (gc *dsAddrBookGc) background() {
|
||||
if gc.lookaheadEnabled {
|
||||
lookaheadTimer := time.NewTicker(gc.ab.opts.GCLookaheadInterval)
|
||||
lookaheadCh = lookaheadTimer.C
|
||||
gc.populateLookahead() // do a lookahead now
|
||||
defer lookaheadTimer.Stop()
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ func TestGCLookahead(t *testing.T) {
|
||||
// effectively disable automatic GC for this test.
|
||||
opts.GCInitialDelay = 90 * time.Hour
|
||||
opts.GCLookaheadInterval = 10 * time.Second
|
||||
opts.GCPurgeInterval = 1 * time.Minute
|
||||
opts.GCPurgeInterval = 1 * time.Second
|
||||
|
||||
factory := addressBookFactory(t, badgerStore, opts)
|
||||
ab, closeFn := factory()
|
||||
@ -88,7 +88,7 @@ func TestGCPurging(t *testing.T) {
|
||||
// effectively disable automatic GC for this test.
|
||||
opts.GCInitialDelay = 90 * time.Hour
|
||||
opts.GCLookaheadInterval = 20 * time.Second
|
||||
opts.GCPurgeInterval = 1 * time.Minute
|
||||
opts.GCPurgeInterval = 1 * time.Second
|
||||
|
||||
factory := addressBookFactory(t, badgerStore, opts)
|
||||
ab, closeFn := factory()
|
||||
@ -154,8 +154,8 @@ func TestGCDelay(t *testing.T) {
|
||||
opts := DefaultOpts()
|
||||
|
||||
opts.GCInitialDelay = 2 * time.Second
|
||||
opts.GCLookaheadInterval = 2 * time.Second
|
||||
opts.GCPurgeInterval = 6 * time.Hour
|
||||
opts.GCLookaheadInterval = 1 * time.Minute
|
||||
opts.GCPurgeInterval = 30 * time.Second
|
||||
|
||||
factory := addressBookFactory(t, badgerStore, opts)
|
||||
ab, closeFn := factory()
|
||||
@ -170,8 +170,8 @@ func TestGCDelay(t *testing.T) {
|
||||
t.Errorf("expected no lookahead entries, got: %d", i)
|
||||
}
|
||||
|
||||
// delay + lookahead interval = 4 seconds + 2 seconds for some slack = 6 seconds.
|
||||
<-time.After(6 * time.Second)
|
||||
// after the initial delay has passed.
|
||||
<-time.After(3 * time.Second)
|
||||
if i := tp.countLookaheadEntries(); i != 1 {
|
||||
t.Errorf("expected 1 lookahead entry, got: %d", i)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user