mirror of
https://github.com/fluencelabs/go-libp2p-kad-dht
synced 2025-04-24 22:32:13 +00:00
correctly tear-down bootstrapper
1. We need to close the process to tear it down. 2. Closing the signal channel will cause the goprocess timer to fire repeatedly so let's not do that. 3. Don't leak a goroutine (the amplify one).
This commit is contained in:
parent
87783c0ed0
commit
b02b9245be
29
dht_test.go
29
dht_test.go
@ -415,20 +415,7 @@ func TestPeriodicBootstrap(t *testing.T) {
|
||||
}
|
||||
}()
|
||||
|
||||
// signal amplifier
|
||||
amplify := func(signal chan time.Time, other []chan time.Time) {
|
||||
for t := range signal {
|
||||
for _, s := range other {
|
||||
s <- t
|
||||
}
|
||||
}
|
||||
for _, s := range other {
|
||||
close(s)
|
||||
}
|
||||
}
|
||||
|
||||
signal := make(chan time.Time)
|
||||
allSignals := []chan time.Time{}
|
||||
signals := []chan time.Time{}
|
||||
|
||||
var cfg BootstrapConfig
|
||||
cfg = DefaultBootstrapConfig
|
||||
@ -437,10 +424,13 @@ func TestPeriodicBootstrap(t *testing.T) {
|
||||
// kick off periodic bootstrappers with instrumented signals.
|
||||
for _, dht := range dhts {
|
||||
s := make(chan time.Time)
|
||||
allSignals = append(allSignals, s)
|
||||
dht.BootstrapOnSignal(cfg, s)
|
||||
signals = append(signals, s)
|
||||
proc, err := dht.BootstrapOnSignal(cfg, s)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer proc.Close()
|
||||
}
|
||||
go amplify(signal, allSignals)
|
||||
|
||||
t.Logf("dhts are not connected. %d", nDHTs)
|
||||
for _, dht := range dhts {
|
||||
@ -467,7 +457,10 @@ func TestPeriodicBootstrap(t *testing.T) {
|
||||
}
|
||||
|
||||
t.Logf("bootstrapping them so they find each other. %d", nDHTs)
|
||||
signal <- time.Now()
|
||||
now := time.Now()
|
||||
for _, signal := range signals {
|
||||
go func(s chan time.Time) { s <- now }(signal)
|
||||
}
|
||||
|
||||
// this is async, and we dont know when it's finished with one cycle, so keep checking
|
||||
// until the routing tables look better, or some long timeout for the failure case.
|
||||
|
Loading…
x
Reference in New Issue
Block a user