Commit a72ba5a5 authored by Janoš Guljaš's avatar Janoš Guljaš Committed by Péter Szilágyi

cmd/swarm, swarm: various test fixes (#17299)

* swarm/network/simulation: increase the sleep duration for TestRun

* cmd/swarm, swarm: fix failing tests on mac

* cmd/swarm: update TestCLISwarmFs skip comment

* swarm/network/simulation: adjust disconnections on simulation close

* swarm/network/simulation: call cleanups after net shutdown
parent 6711f098
...@@ -92,7 +92,7 @@ func listMounts(cliContext *cli.Context) { ...@@ -92,7 +92,7 @@ func listMounts(cliContext *cli.Context) {
mf := []fuse.MountInfo{} mf := []fuse.MountInfo{}
err = client.CallContext(ctx, &mf, "swarmfs_listmounts") err = client.CallContext(ctx, &mf, "swarmfs_listmounts")
if err != nil { if err != nil {
utils.Fatalf("encountered an error calling the RPC endpoint while unmounting: %v", err) utils.Fatalf("encountered an error calling the RPC endpoint while listing mounts: %v", err)
} }
if len(mf) == 0 { if len(mf) == 0 {
fmt.Print("Could not found any swarmfs mounts. Please make sure you've specified the correct RPC endpoint\n") fmt.Print("Could not found any swarmfs mounts. Please make sure you've specified the correct RPC endpoint\n")
......
...@@ -44,6 +44,11 @@ type testFile struct { ...@@ -44,6 +44,11 @@ type testFile struct {
// TestCLISwarmFs is a high-level test of swarmfs // TestCLISwarmFs is a high-level test of swarmfs
func TestCLISwarmFs(t *testing.T) { func TestCLISwarmFs(t *testing.T) {
// This test fails on travis as this executable exits with code 1
// and without any log messages in the log.
// /Library/Filesystems/osxfuse.fs/Contents/Resources/load_osxfuse
t.Skip()
cluster := newTestCluster(t, 3) cluster := newTestCluster(t, 3)
defer cluster.Shutdown() defer cluster.Shutdown()
......
...@@ -62,6 +62,8 @@ type Simulation struct { ...@@ -62,6 +62,8 @@ type Simulation struct {
// where all "global" state related to the service should be kept. // where all "global" state related to the service should be kept.
// All cleanups needed for constructed service and any other constructed // All cleanups needed for constructed service and any other constructed
// objects should ne provided in a single returned cleanup function. // objects should ne provided in a single returned cleanup function.
// Returned cleanup function will be called by Close function
// after network shutdown.
type ServiceFunc func(ctx *adapters.ServiceContext, bucket *sync.Map) (s node.Service, cleanup func(), err error) type ServiceFunc func(ctx *adapters.ServiceContext, bucket *sync.Map) (s node.Service, cleanup func(), err error)
// New creates a new Simulation instance with new // New creates a new Simulation instance with new
...@@ -161,6 +163,18 @@ var maxParallelCleanups = 10 ...@@ -161,6 +163,18 @@ var maxParallelCleanups = 10
// simulation. // simulation.
func (s *Simulation) Close() { func (s *Simulation) Close() {
close(s.done) close(s.done)
// Close all connections before calling the Network Shutdown.
// It is possible that p2p.Server.Stop will block if there are
// existing connections.
for _, c := range s.Net.Conns {
if c.Up {
s.Net.Disconnect(c.One, c.Other)
}
}
s.shutdownWG.Wait()
s.Net.Shutdown()
sem := make(chan struct{}, maxParallelCleanups) sem := make(chan struct{}, maxParallelCleanups)
s.mu.RLock() s.mu.RLock()
cleanupFuncs := make([]func(), len(s.cleanupFuncs)) cleanupFuncs := make([]func(), len(s.cleanupFuncs))
...@@ -170,16 +184,19 @@ func (s *Simulation) Close() { ...@@ -170,16 +184,19 @@ func (s *Simulation) Close() {
} }
} }
s.mu.RUnlock() s.mu.RUnlock()
var cleanupWG sync.WaitGroup
for _, cleanup := range cleanupFuncs { for _, cleanup := range cleanupFuncs {
s.shutdownWG.Add(1) cleanupWG.Add(1)
sem <- struct{}{} sem <- struct{}{}
go func(cleanup func()) { go func(cleanup func()) {
defer s.shutdownWG.Done() defer cleanupWG.Done()
defer func() { <-sem }() defer func() { <-sem }()
cleanup() cleanup()
}(cleanup) }(cleanup)
} }
cleanupWG.Wait()
if s.httpSrv != nil { if s.httpSrv != nil {
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel() defer cancel()
...@@ -189,8 +206,6 @@ func (s *Simulation) Close() { ...@@ -189,8 +206,6 @@ func (s *Simulation) Close() {
} }
close(s.runC) close(s.runC)
} }
s.shutdownWG.Wait()
s.Net.Shutdown()
} }
// Done returns a channel that is closed when the simulation // Done returns a channel that is closed when the simulation
......
...@@ -68,7 +68,7 @@ func TestRun(t *testing.T) { ...@@ -68,7 +68,7 @@ func TestRun(t *testing.T) {
defer cancel() defer cancel()
r := sim.Run(ctx, func(ctx context.Context, sim *Simulation) error { r := sim.Run(ctx, func(ctx context.Context, sim *Simulation) error {
time.Sleep(100 * time.Millisecond) time.Sleep(time.Second)
return nil return nil
}) })
......
...@@ -393,6 +393,11 @@ func testDeliveryFromNodes(t *testing.T, nodes, conns, chunkCount int, skipCheck ...@@ -393,6 +393,11 @@ func testDeliveryFromNodes(t *testing.T, nodes, conns, chunkCount int, skipCheck
return err return err
} }
log.Debug("Waiting for kademlia")
if _, err := sim.WaitTillHealthy(ctx, 2); err != nil {
return err
}
//each of the nodes (except pivot node) subscribes to the stream of the next node //each of the nodes (except pivot node) subscribes to the stream of the next node
for j, node := range nodeIDs[0 : nodes-1] { for j, node := range nodeIDs[0 : nodes-1] {
sid := nodeIDs[j+1] sid := nodeIDs[j+1]
...@@ -424,11 +429,6 @@ func testDeliveryFromNodes(t *testing.T, nodes, conns, chunkCount int, skipCheck ...@@ -424,11 +429,6 @@ func testDeliveryFromNodes(t *testing.T, nodes, conns, chunkCount int, skipCheck
} }
}() }()
log.Debug("Waiting for kademlia")
if _, err := sim.WaitTillHealthy(ctx, 2); err != nil {
return err
}
log.Debug("Watching for disconnections") log.Debug("Watching for disconnections")
disconnections := sim.PeerEvents( disconnections := sim.PeerEvents(
context.Background(), context.Background(),
......
...@@ -246,6 +246,8 @@ func testSyncingViaGlobalSync(t *testing.T, chunkCount int, nodeCount int) { ...@@ -246,6 +246,8 @@ func testSyncingViaGlobalSync(t *testing.T, chunkCount int, nodeCount int) {
if err != nil { if err != nil {
log.Warn(fmt.Sprintf("Chunk %s NOT found for id %s", chunk, id)) log.Warn(fmt.Sprintf("Chunk %s NOT found for id %s", chunk, id))
localSuccess = false localSuccess = false
// Do not get crazy with logging the warn message
time.Sleep(500 * time.Millisecond)
} else { } else {
log.Debug(fmt.Sprintf("Chunk %s IS FOUND for id %s", chunk, id)) log.Debug(fmt.Sprintf("Chunk %s IS FOUND for id %s", chunk, id))
} }
...@@ -426,6 +428,8 @@ func testSyncingViaDirectSubscribe(chunkCount int, nodeCount int) error { ...@@ -426,6 +428,8 @@ func testSyncingViaDirectSubscribe(chunkCount int, nodeCount int) error {
if err != nil { if err != nil {
log.Warn(fmt.Sprintf("Chunk %s NOT found for id %s", chunk, id)) log.Warn(fmt.Sprintf("Chunk %s NOT found for id %s", chunk, id))
localSuccess = false localSuccess = false
// Do not get crazy with logging the warn message
time.Sleep(500 * time.Millisecond)
} else { } else {
log.Debug(fmt.Sprintf("Chunk %s IS FOUND for id %s", chunk, id)) log.Debug(fmt.Sprintf("Chunk %s IS FOUND for id %s", chunk, id))
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment