Skip to content

Commit

Permalink
bitswap: mark all hybrid, client, server and network tests flaky
Browse files Browse the repository at this point in the history
I've applied the jackhammer approach, there is probably correct tests in
this set, but I'll leave finding them (and fixing bad ones) to someone
else (including potentially future me).

To enable flaky tests pass RUN_FLAKY_TESTS=1 environement variable.
  • Loading branch information
Jorropo committed Jan 27, 2023
1 parent c3491de commit 0a9cfb6
Show file tree
Hide file tree
Showing 26 changed files with 399 additions and 19 deletions.
32 changes: 32 additions & 0 deletions bitswap/bitswap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
testinstance "github.com/ipfs/go-libipfs/bitswap/testinstance"
tn "github.com/ipfs/go-libipfs/bitswap/testnet"
blocks "github.com/ipfs/go-libipfs/blocks"
"github.com/ipfs/go-libipfs/internal/test"
tu "github.com/libp2p/go-libp2p-testing/etc"
p2ptestutil "github.com/libp2p/go-libp2p-testing/netutil"
peer "github.com/libp2p/go-libp2p/core/peer"
Expand Down Expand Up @@ -48,6 +49,8 @@ func addBlock(t *testing.T, ctx context.Context, inst testinstance.Instance, blk
const kNetworkDelay = 0 * time.Millisecond

func TestClose(t *testing.T) {
test.Flaky(t)

vnet := tn.VirtualNetwork(mockrouting.NewServer(), delay.Fixed(kNetworkDelay))
ig := testinstance.NewTestInstanceGenerator(vnet, nil, nil)
defer ig.Close()
Expand All @@ -64,6 +67,7 @@ func TestClose(t *testing.T) {
}

func TestProviderForKeyButNetworkCannotFind(t *testing.T) { // TODO revisit this
test.Flaky(t)

rs := mockrouting.NewServer()
net := tn.VirtualNetwork(rs, delay.Fixed(kNetworkDelay))
Expand All @@ -90,6 +94,7 @@ func TestProviderForKeyButNetworkCannotFind(t *testing.T) { // TODO revisit this
}

func TestGetBlockFromPeerAfterPeerAnnounces(t *testing.T) {
test.Flaky(t)

net := tn.VirtualNetwork(mockrouting.NewServer(), delay.Fixed(kNetworkDelay))
block := blocks.NewBlock([]byte("block"))
Expand Down Expand Up @@ -119,6 +124,8 @@ func TestGetBlockFromPeerAfterPeerAnnounces(t *testing.T) {
}

func TestDoesNotProvideWhenConfiguredNotTo(t *testing.T) {
test.Flaky(t)

net := tn.VirtualNetwork(mockrouting.NewServer(), delay.Fixed(kNetworkDelay))
block := blocks.NewBlock([]byte("block"))
bsOpts := []bitswap.Option{bitswap.ProvideEnabled(false), bitswap.ProviderSearchDelay(50 * time.Millisecond)}
Expand Down Expand Up @@ -151,6 +158,7 @@ func TestDoesNotProvideWhenConfiguredNotTo(t *testing.T) {
// Tests that a received block is not stored in the blockstore if the block was
// not requested by the client
func TestUnwantedBlockNotAdded(t *testing.T) {
test.Flaky(t)

net := tn.VirtualNetwork(mockrouting.NewServer(), delay.Fixed(kNetworkDelay))
block := blocks.NewBlock([]byte("block"))
Expand Down Expand Up @@ -187,6 +195,8 @@ func TestUnwantedBlockNotAdded(t *testing.T) {
//
// (because the live request queue is full)
func TestPendingBlockAdded(t *testing.T) {
test.Flaky(t)

ctx := context.Background()
net := tn.VirtualNetwork(mockrouting.NewServer(), delay.Fixed(kNetworkDelay))
bg := blocksutil.NewBlockGenerator()
Expand Down Expand Up @@ -235,6 +245,8 @@ func TestPendingBlockAdded(t *testing.T) {
}

func TestLargeSwarm(t *testing.T) {
test.Flaky(t)

if testing.Short() {
t.SkipNow()
}
Expand Down Expand Up @@ -267,6 +279,8 @@ func TestLargeFile(t *testing.T) {
}

func TestLargeFileTwoPeers(t *testing.T) {
test.Flaky(t)

if testing.Short() {
t.SkipNow()
}
Expand All @@ -276,6 +290,8 @@ func TestLargeFileTwoPeers(t *testing.T) {
}

func PerformDistributionTest(t *testing.T, numInstances, numBlocks int) {
test.Flaky(t)

ctx := context.Background()
if testing.Short() {
t.SkipNow()
Expand Down Expand Up @@ -333,6 +349,8 @@ func PerformDistributionTest(t *testing.T, numInstances, numBlocks int) {

// TODO simplify this test. get to the _essence_!
func TestSendToWantingPeer(t *testing.T) {
test.Flaky(t)

if testing.Short() {
t.SkipNow()
}
Expand Down Expand Up @@ -376,6 +394,8 @@ func TestSendToWantingPeer(t *testing.T) {
}

func TestEmptyKey(t *testing.T) {
test.Flaky(t)

net := tn.VirtualNetwork(mockrouting.NewServer(), delay.Fixed(kNetworkDelay))
ig := testinstance.NewTestInstanceGenerator(net, nil, nil)
defer ig.Close()
Expand Down Expand Up @@ -409,6 +429,8 @@ func assertStat(t *testing.T, st *bitswap.Stat, sblks, rblks, sdata, rdata uint6
}

func TestBasicBitswap(t *testing.T) {
test.Flaky(t)

net := tn.VirtualNetwork(mockrouting.NewServer(), delay.Fixed(kNetworkDelay))
ig := testinstance.NewTestInstanceGenerator(net, nil, nil)
defer ig.Close()
Expand Down Expand Up @@ -481,6 +503,8 @@ func TestBasicBitswap(t *testing.T) {
}

func TestDoubleGet(t *testing.T) {
test.Flaky(t)

net := tn.VirtualNetwork(mockrouting.NewServer(), delay.Fixed(kNetworkDelay))
ig := testinstance.NewTestInstanceGenerator(net, nil, nil)
defer ig.Close()
Expand Down Expand Up @@ -546,6 +570,8 @@ func TestDoubleGet(t *testing.T) {
}

func TestWantlistCleanup(t *testing.T) {
test.Flaky(t)

net := tn.VirtualNetwork(mockrouting.NewServer(), delay.Fixed(kNetworkDelay))
ig := testinstance.NewTestInstanceGenerator(net, nil, nil)
defer ig.Close()
Expand Down Expand Up @@ -668,6 +694,8 @@ func newReceipt(sent, recv, exchanged uint64) *server.Receipt {
}

func TestBitswapLedgerOneWay(t *testing.T) {
test.Flaky(t)

net := tn.VirtualNetwork(mockrouting.NewServer(), delay.Fixed(kNetworkDelay))
ig := testinstance.NewTestInstanceGenerator(net, nil, nil)
defer ig.Close()
Expand Down Expand Up @@ -717,6 +745,8 @@ func TestBitswapLedgerOneWay(t *testing.T) {
}

func TestBitswapLedgerTwoWay(t *testing.T) {
test.Flaky(t)

net := tn.VirtualNetwork(mockrouting.NewServer(), delay.Fixed(kNetworkDelay))
ig := testinstance.NewTestInstanceGenerator(net, nil, nil)
defer ig.Close()
Expand Down Expand Up @@ -804,6 +834,8 @@ func (tsl *testingScoreLedger) Stop() {

// Tests start and stop of a custom decision logic
func TestWithScoreLedger(t *testing.T) {
test.Flaky(t)

tsl := newTestingScoreLedger()
net := tn.VirtualNetwork(mockrouting.NewServer(), delay.Fixed(kNetworkDelay))
bsOpts := []bitswap.Option{bitswap.WithScoreLedger(tsl)}
Expand Down
19 changes: 19 additions & 0 deletions bitswap/client/bitswap_with_sessions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
testinstance "github.com/ipfs/go-libipfs/bitswap/testinstance"
tn "github.com/ipfs/go-libipfs/bitswap/testnet"
blocks "github.com/ipfs/go-libipfs/blocks"
"github.com/ipfs/go-libipfs/internal/test"
tu "github.com/libp2p/go-libp2p-testing/etc"
)

Expand All @@ -37,6 +38,8 @@ func addBlock(t *testing.T, ctx context.Context, inst testinstance.Instance, blk
}

func TestBasicSessions(t *testing.T) {
test.Flaky(t)

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

Expand Down Expand Up @@ -88,6 +91,8 @@ func assertBlockLists(got, exp []blocks.Block) error {
}

func TestSessionBetweenPeers(t *testing.T) {
test.Flaky(t)

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

Expand Down Expand Up @@ -148,6 +153,8 @@ func TestSessionBetweenPeers(t *testing.T) {
}

func TestSessionSplitFetch(t *testing.T) {
test.Flaky(t)

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

Expand Down Expand Up @@ -192,6 +199,8 @@ func TestSessionSplitFetch(t *testing.T) {
}

func TestFetchNotConnected(t *testing.T) {
test.Flaky(t)

ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()

Expand Down Expand Up @@ -235,6 +244,8 @@ func TestFetchNotConnected(t *testing.T) {
}

func TestFetchAfterDisconnect(t *testing.T) {
test.Flaky(t)

ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()

Expand Down Expand Up @@ -313,6 +324,8 @@ func TestFetchAfterDisconnect(t *testing.T) {
}

func TestInterestCacheOverflow(t *testing.T) {
test.Flaky(t)

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

Expand Down Expand Up @@ -363,6 +376,8 @@ func TestInterestCacheOverflow(t *testing.T) {
}

func TestPutAfterSessionCacheEvict(t *testing.T) {
test.Flaky(t)

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

Expand Down Expand Up @@ -401,6 +416,8 @@ func TestPutAfterSessionCacheEvict(t *testing.T) {
}

func TestMultipleSessions(t *testing.T) {
test.Flaky(t)

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

Expand Down Expand Up @@ -442,6 +459,8 @@ func TestMultipleSessions(t *testing.T) {
}

func TestWantlistClearsOnCancel(t *testing.T) {
test.Flaky(t)

ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package blockpresencemanager
import (
"testing"

cid "github.com/ipfs/go-cid"
"github.com/ipfs/go-libipfs/bitswap/internal/testutil"
"github.com/ipfs/go-libipfs/internal/test"
peer "github.com/libp2p/go-libp2p/core/peer"

cid "github.com/ipfs/go-cid"
)

const (
Expand All @@ -17,6 +17,8 @@ const (
)

func TestBlockPresenceManager(t *testing.T) {
test.Flaky(t)

bpm := New()

p := testutil.GeneratePeers(1)[0]
Expand Down Expand Up @@ -97,6 +99,8 @@ func TestBlockPresenceManager(t *testing.T) {
}

func TestAddRemoveMulti(t *testing.T) {
test.Flaky(t)

bpm := New()

peers := testutil.GeneratePeers(2)
Expand Down Expand Up @@ -180,6 +184,8 @@ func TestAddRemoveMulti(t *testing.T) {
}

func TestAllPeersDoNotHaveBlock(t *testing.T) {
test.Flaky(t)

bpm := New()

peers := testutil.GeneratePeers(3)
Expand Down
19 changes: 19 additions & 0 deletions bitswap/client/internal/messagequeue/donthavetimeoutmgr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/benbjohnson/clock"
cid "github.com/ipfs/go-cid"
"github.com/ipfs/go-libipfs/bitswap/internal/testutil"
"github.com/ipfs/go-libipfs/internal/test"
"github.com/libp2p/go-libp2p/p2p/protocol/ping"
)

Expand Down Expand Up @@ -73,6 +74,8 @@ func (tr *timeoutRecorder) clear() {
}

func TestDontHaveTimeoutMgrTimeout(t *testing.T) {
test.Flaky(t)

firstks := testutil.GenerateCids(2)
secondks := append(firstks, testutil.GenerateCids(3)...)
latency := time.Millisecond * 20
Expand Down Expand Up @@ -129,6 +132,8 @@ func TestDontHaveTimeoutMgrTimeout(t *testing.T) {
}

func TestDontHaveTimeoutMgrCancel(t *testing.T) {
test.Flaky(t)

ks := testutil.GenerateCids(3)
latency := time.Millisecond * 10
latMultiplier := 1
Expand Down Expand Up @@ -165,6 +170,8 @@ func TestDontHaveTimeoutMgrCancel(t *testing.T) {
}

func TestDontHaveTimeoutWantCancelWant(t *testing.T) {
test.Flaky(t)

ks := testutil.GenerateCids(3)
latency := time.Millisecond * 20
latMultiplier := 1
Expand Down Expand Up @@ -218,6 +225,8 @@ func TestDontHaveTimeoutWantCancelWant(t *testing.T) {
}

func TestDontHaveTimeoutRepeatedAddPending(t *testing.T) {
test.Flaky(t)

ks := testutil.GenerateCids(10)
latency := time.Millisecond * 5
latMultiplier := 1
Expand Down Expand Up @@ -251,6 +260,8 @@ func TestDontHaveTimeoutRepeatedAddPending(t *testing.T) {
}

func TestDontHaveTimeoutMgrMessageLatency(t *testing.T) {
test.Flaky(t)

ks := testutil.GenerateCids(2)
latency := time.Millisecond * 40
latMultiplier := 1
Expand Down Expand Up @@ -300,6 +311,8 @@ func TestDontHaveTimeoutMgrMessageLatency(t *testing.T) {
}

func TestDontHaveTimeoutMgrMessageLatencyMax(t *testing.T) {
test.Flaky(t)

ks := testutil.GenerateCids(2)
clock := clock.NewMock()
pinged := make(chan struct{})
Expand Down Expand Up @@ -333,6 +346,8 @@ func TestDontHaveTimeoutMgrMessageLatencyMax(t *testing.T) {
}

func TestDontHaveTimeoutMgrUsesDefaultTimeoutIfPingError(t *testing.T) {
test.Flaky(t)

ks := testutil.GenerateCids(2)
latency := time.Millisecond * 1
latMultiplier := 2
Expand Down Expand Up @@ -374,6 +389,8 @@ func TestDontHaveTimeoutMgrUsesDefaultTimeoutIfPingError(t *testing.T) {
}

func TestDontHaveTimeoutMgrUsesDefaultTimeoutIfLatencyLonger(t *testing.T) {
test.Flaky(t)

ks := testutil.GenerateCids(2)
latency := time.Millisecond * 200
latMultiplier := 1
Expand Down Expand Up @@ -414,6 +431,8 @@ func TestDontHaveTimeoutMgrUsesDefaultTimeoutIfLatencyLonger(t *testing.T) {
}

func TestDontHaveTimeoutNoTimeoutAfterShutdown(t *testing.T) {
test.Flaky(t)

ks := testutil.GenerateCids(2)
latency := time.Millisecond * 10
latMultiplier := 1
Expand Down
Loading

0 comments on commit 0a9cfb6

Please sign in to comment.