mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-26 21:07:45 +08:00
Updates: * go-kad-dht: Query performance improvements, DHT client fixes, validates records on *local* put. * go-libp2p-swarm/go-libp2p-transport: Timeout improvements. * go-multiaddr-net: Exposes useful Conn methods (CloseWrite, CloseRead, etc.) * go-log: fixes possible panic when enabling/disabling events. * go-multiaddr: fixes possible panic when stringifying malformed multiaddrs, adds support for consuming /p2p/ multiaddrs. fixes #5113 unblocks #4895 License: MIT Signed-off-by: Steven Allen <steven@stebalien.com>
78 lines
1.2 KiB
Go
78 lines
1.2 KiB
Go
package mfs
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
cid "gx/ipfs/QmapdYm1b22Frv3k17fqrBYTFRxwiaVJkB299Mfn33edeB/go-cid"
|
|
ci "gx/ipfs/QmcW4FGAt24fdK1jBgWQn3yP4R9ZLyWQqjozv9QK7epRhL/go-testutil/ci"
|
|
)
|
|
|
|
func TestRepublisher(t *testing.T) {
|
|
if ci.IsRunning() {
|
|
t.Skip("dont run timing tests in CI")
|
|
}
|
|
|
|
ctx := context.TODO()
|
|
|
|
pub := make(chan struct{})
|
|
|
|
pf := func(ctx context.Context, c *cid.Cid) error {
|
|
pub <- struct{}{}
|
|
return nil
|
|
}
|
|
|
|
tshort := time.Millisecond * 50
|
|
tlong := time.Second / 2
|
|
|
|
rp := NewRepublisher(ctx, pf, tshort, tlong)
|
|
go rp.Run()
|
|
|
|
rp.Update(nil)
|
|
|
|
// should hit short timeout
|
|
select {
|
|
case <-time.After(tshort * 2):
|
|
t.Fatal("publish didnt happen in time")
|
|
case <-pub:
|
|
}
|
|
|
|
cctx, cancel := context.WithCancel(context.Background())
|
|
|
|
go func() {
|
|
for {
|
|
rp.Update(nil)
|
|
time.Sleep(time.Millisecond * 10)
|
|
select {
|
|
case <-cctx.Done():
|
|
return
|
|
default:
|
|
}
|
|
}
|
|
}()
|
|
|
|
select {
|
|
case <-pub:
|
|
t.Fatal("shouldnt have received publish yet!")
|
|
case <-time.After((tlong * 9) / 10):
|
|
}
|
|
select {
|
|
case <-pub:
|
|
case <-time.After(tlong / 2):
|
|
t.Fatal("waited too long for pub!")
|
|
}
|
|
|
|
cancel()
|
|
|
|
go func() {
|
|
err := rp.Close()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}()
|
|
|
|
// final pub from closing
|
|
<-pub
|
|
}
|