From 4fd234bb05be3fbd89569ba9794bf123fed15ad2 Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Fri, 16 Mar 2018 17:37:39 +0100 Subject: [PATCH] Fix #339: Reduce Sleeps in tests License: MIT Signed-off-by: Hector Sanjuan --- cluster.go | 3 +- cluster_test.go | 2 +- config/config.go | 3 +- config_test.go | 25 ++-- consensus/raft/consensus_test.go | 2 + ipfscluster_test.go | 201 ++++++++++++++++++------------- monitor/basic/peer_monitor.go | 3 +- peer_manager_test.go | 20 ++- pnet_test.go | 47 ++++---- 9 files changed, 170 insertions(+), 136 deletions(-) diff --git a/cluster.go b/cluster.go index 9f5908951..cd4f39bcb 100644 --- a/cluster.go +++ b/cluster.go @@ -270,7 +270,6 @@ func (c *Cluster) pushInformerMetrics() { // The following control how often to make and log // a retry retries := 0 - retryDelay := 500 * time.Millisecond retryWarnMod := 60 for { select { @@ -291,7 +290,7 @@ func (c *Cluster) pushInformerMetrics() { retries++ } // retry in retryDelay - timer.Reset(retryDelay) + timer.Reset(metric.GetTTL() / 4) continue } diff --git a/cluster_test.go b/cluster_test.go index 003e07238..dab7a6915 100644 --- a/cluster_test.go +++ b/cluster_test.go @@ -314,7 +314,7 @@ func TestClusterRecoverAllLocal(t *testing.T) { t.Fatal("pin should have worked:", err) } - time.Sleep(time.Second) + pinDelay() recov, err := cl.RecoverAllLocal() if err != nil { diff --git a/config/config.go b/config/config.go index fbb5889ff..bf55bc863 100644 --- a/config/config.go +++ b/config/config.go @@ -15,7 +15,8 @@ import ( var logger = logging.Logger("config") -// How often to save the configuration file if it needs saving. +// ConfigSaveInterval specifies how often to save the configuration file if +// it needs saving. var ConfigSaveInterval = time.Second // The ComponentConfig interface allows components to define configurations diff --git a/config_test.go b/config_test.go index 22a7c63e6..324725725 100644 --- a/config_test.go +++ b/config_test.go @@ -17,29 +17,30 @@ var testingClusterCfg = []byte(`{ "secret": "2588b80d5cb05374fa142aed6cbb047d1f4ef8ef15e37eba68c65b9d30df67ed", "peers": [], "bootstrap": [], - "leave_on_shutdown": true, + "leave_on_shutdown": false, "listen_multiaddress": "/ip4/127.0.0.1/tcp/10000", "state_sync_interval": "1m0s", "ipfs_sync_interval": "2m10s", "replication_factor": -1, - "monitor_ping_interval": "1s" + "monitor_ping_interval": "150ms", + "peer_watch_interval": "100ms" } `) var testingRaftCfg = []byte(`{ "data_folder": "raftFolderFromTests", - "wait_for_leader_timeout": "30s", - "commit_retries": 1, - "commit_retry_delay": "1s", - "network_timeout": "20s", - "heartbeat_timeout": "1s", - "election_timeout": "1s", + "wait_for_leader_timeout": "10s", + "commit_retries": 2, + "commit_retry_delay": "50ms", + "network_timeout": "5s", + "heartbeat_timeout": "100ms", + "election_timeout": "100ms", "commit_timeout": "50ms", - "max_append_entries": 64, + "max_append_entries": 256, "trailing_logs": 10240, "snapshot_interval": "2m0s", "snapshot_threshold": 8192, - "leader_lease_timeout": "500ms" + "leader_lease_timeout": "80ms" }`) var testingAPICfg = []byte(`{ @@ -71,11 +72,11 @@ var testingTrackerCfg = []byte(` `) var testingMonCfg = []byte(`{ - "check_interval": "1s" + "check_interval": "400ms" }`) var testingDiskInfCfg = []byte(`{ - "metric_ttl": "1s", + "metric_ttl": "150ms", "metric_type": "freespace" }`) diff --git a/consensus/raft/consensus_test.go b/consensus/raft/consensus_test.go index 112339e38..b677d4ad0 100644 --- a/consensus/raft/consensus_test.go +++ b/consensus/raft/consensus_test.go @@ -59,6 +59,7 @@ func makeTestingHost(t *testing.T) host.Host { } func testingConsensus(t *testing.T, idn int) *Consensus { + cleanRaft(idn) h := makeTestingHost(t) st := mapstate.NewMapState() @@ -81,6 +82,7 @@ func TestShutdownConsensus(t *testing.T) { // Bring it up twice to make sure shutdown cleans up properly // but also to make sure raft comes up ok when re-initialized cc := testingConsensus(t, 1) + defer cleanRaft(1) err := cc.Shutdown() if err != nil { t.Fatal("Consensus cannot shutdown:", err) diff --git a/ipfscluster_test.go b/ipfscluster_test.go index e8728508b..9e1c05a3c 100644 --- a/ipfscluster_test.go +++ b/ipfscluster_test.go @@ -35,7 +35,7 @@ var ( nClusters = 6 // number of pins to pin/unpin/check - nPins = 500 + nPins = 100 logLevel = "CRITICAL" @@ -207,15 +207,26 @@ func createClusters(t *testing.T) ([]*Cluster, []*test.IpfsMock) { } // Start the rest - var wg sync.WaitGroup + // Doing this in parallel causes libp2p dial backoffs for i := 1; i < nClusters; i++ { - wg.Add(1) - go func(i int) { - clusters[i] = createCluster(t, cfgs[i], concfgs[i], apis[i], ipfss[i], states[i], trackers[i], mons[i], allocs[i], infs[i]) - wg.Done() - }(i) + clusters[i] = createCluster(t, cfgs[i], concfgs[i], apis[i], ipfss[i], states[i], trackers[i], mons[i], allocs[i], infs[i]) + time.Sleep(100 * time.Millisecond) + } + + // open connections among all peers. This ensures smoother operations. + // Best effort. Some errors do happen. + for _, c := range clusters { + peers, err := c.consensus.Peers() + if err != nil { + shutdownClusters(t, clusters, ipfsMocks) + t.Fatal(err) + } + for _, p := range peers { + if p != c.id { + c.host.Network().DialPeer(c.ctx, p) + } + } } - wg.Wait() // --------------------------------------------- @@ -223,8 +234,7 @@ func createClusters(t *testing.T) ([]*Cluster, []*test.IpfsMock) { // for i := 1; i < nClusters; i++ { // clusters[0].PeerAdd(clusterAddr(clusters[i])) // } - delay() - delay() + return clusters, ipfsMocks } @@ -255,26 +265,31 @@ func runF(t *testing.T, clusters []*Cluster, f func(*testing.T, *Cluster)) { func delay() { var d int if nClusters > 10 { - d = 8 - - } else if nClusters > 5 { - d = 5 + d = 2000 } else { - d = nClusters + d = 1000 } - time.Sleep(time.Duration(d) * time.Second) + time.Sleep(time.Duration(d) * time.Millisecond) +} + +func pinDelay() { + time.Sleep(300 * time.Millisecond) +} + +func ttlDelay() { + diskInfCfg := &disk.Config{} + diskInfCfg.LoadJSON(testingDiskInfCfg) + time.Sleep(diskInfCfg.MetricTTL * 3) } +// Waits for consensus to pick a new leader in case we shut it down +// Makes sure all peers know about it. +// Makes sure new metrics have come in for the new leader. func waitForLeader(t *testing.T, clusters []*Cluster) { - timer := time.NewTimer(time.Minute) - ticker := time.NewTicker(time.Second) - // Wait for consensus to pick a new leader in case we shut it down + ttlDelay() - // Make sure we don't check on a shutdown cluster - j := rand.Intn(len(clusters)) - for clusters[j].shutdownB { - j = rand.Intn(len(clusters)) - } + timer := time.NewTimer(time.Minute) + ticker := time.NewTicker(time.Second / 4) loop: for { @@ -282,12 +297,20 @@ loop: case <-timer.C: t.Fatal("timed out waiting for a leader") case <-ticker.C: - _, err := clusters[j].consensus.Leader() - if err == nil { - break loop + for _, cl := range clusters { + if cl.shutdownB { + continue // skip shutdown clusters + } + _, err := cl.consensus.Leader() + if err != nil { + continue loop + } } + break loop } } + + ttlDelay() } func TestClustersVersion(t *testing.T) { @@ -305,7 +328,6 @@ func TestClustersVersion(t *testing.T) { func TestClustersPeers(t *testing.T) { clusters, mock := createClusters(t) defer shutdownClusters(t, clusters, mock) - delay() j := rand.Intn(nClusters) // choose a random cluster peer peers := clusters[j].Peers() @@ -345,6 +367,9 @@ func TestClustersPin(t *testing.T) { defer shutdownClusters(t, clusters, mock) exampleCid, _ := cid.Decode(test.TestCid1) prefix := exampleCid.Prefix() + + ttlDelay() + for i := 0; i < nPins; i++ { j := rand.Intn(nClusters) // choose a random cluster peer h, err := prefix.Sum(randomBytes()) // create random cid @@ -360,6 +385,7 @@ func TestClustersPin(t *testing.T) { } } delay() + delay() fpinned := func(t *testing.T, c *Cluster) { status := c.tracker.StatusAll() for _, v := range status { @@ -378,7 +404,7 @@ func TestClustersPin(t *testing.T) { // Unpin everything pinList := clusters[0].Pins() - for i := 0; i < nPins; i++ { + for i := 0; i < len(pinList); i++ { j := rand.Intn(nClusters) // choose a random cluster peer err := clusters[j].Unpin(pinList[i].Cid) if err != nil { @@ -392,6 +418,7 @@ func TestClustersPin(t *testing.T) { } delay() + delay() funpinned := func(t *testing.T, c *Cluster) { status := c.tracker.StatusAll() @@ -408,7 +435,7 @@ func TestClustersStatusAll(t *testing.T) { defer shutdownClusters(t, clusters, mock) h, _ := cid.Decode(test.TestCid1) clusters[0].Pin(api.PinCid(h)) - delay() + pinDelay() // Global status f := func(t *testing.T, c *Cluster) { statuses, err := c.StatusAll() @@ -452,10 +479,11 @@ func TestClustersStatusAllWithErrors(t *testing.T) { defer shutdownClusters(t, clusters, mock) h, _ := cid.Decode(test.TestCid1) clusters[0].Pin(api.PinCid(h)) - delay() + pinDelay() // shutdown 1 cluster peer clusters[1].Shutdown() + delay() f := func(t *testing.T, c *Cluster) { // skip if it's the shutdown peer @@ -513,7 +541,9 @@ func TestClustersSyncAllLocal(t *testing.T) { h2, _ := cid.Decode(test.TestCid2) clusters[0].Pin(api.PinCid(h)) clusters[0].Pin(api.PinCid(h2)) - delay() + pinDelay() + pinDelay() + f := func(t *testing.T, c *Cluster) { // Sync bad ID infos, err := c.SyncAllLocal() @@ -541,7 +571,8 @@ func TestClustersSyncLocal(t *testing.T) { h2, _ := cid.Decode(test.TestCid2) clusters[0].Pin(api.PinCid(h)) clusters[0].Pin(api.PinCid(h2)) - delay() + pinDelay() + pinDelay() f := func(t *testing.T, c *Cluster) { info, err := c.SyncLocal(h) @@ -572,7 +603,8 @@ func TestClustersSyncAll(t *testing.T) { h2, _ := cid.Decode(test.TestCid2) clusters[0].Pin(api.PinCid(h)) clusters[0].Pin(api.PinCid(h2)) - delay() + pinDelay() + pinDelay() j := rand.Intn(nClusters) // choose a random cluster peer ginfos, err := clusters[j].SyncAll() @@ -603,7 +635,8 @@ func TestClustersSync(t *testing.T) { h2, _ := cid.Decode(test.TestCid2) clusters[0].Pin(api.PinCid(h)) clusters[0].Pin(api.PinCid(h2)) - delay() + pinDelay() + pinDelay() j := rand.Intn(nClusters) ginfo, err := clusters[j].Sync(h) @@ -662,10 +695,13 @@ func TestClustersRecoverLocal(t *testing.T) { defer shutdownClusters(t, clusters, mock) h, _ := cid.Decode(test.ErrorCid) // This cid always fails h2, _ := cid.Decode(test.TestCid2) + + ttlDelay() + clusters[0].Pin(api.PinCid(h)) clusters[0].Pin(api.PinCid(h2)) - - delay() + pinDelay() + pinDelay() f := func(t *testing.T, c *Cluster) { info, err := c.RecoverLocal(h) @@ -694,10 +730,14 @@ func TestClustersRecover(t *testing.T) { defer shutdownClusters(t, clusters, mock) h, _ := cid.Decode(test.ErrorCid) // This cid always fails h2, _ := cid.Decode(test.TestCid2) + + ttlDelay() + clusters[0].Pin(api.PinCid(h)) clusters[0].Pin(api.PinCid(h2)) - delay() + pinDelay() + pinDelay() j := rand.Intn(nClusters) ginfo, err := clusters[j].Recover(h) @@ -771,6 +811,8 @@ func TestClustersReplication(t *testing.T) { c.config.ReplicationFactorMax = nClusters - 1 } + ttlDelay() + // Why is replication factor nClusters - 1? // Because that way we know that pinning nCluster // pins with an strategy like numpins/disk @@ -789,7 +831,7 @@ func TestClustersReplication(t *testing.T) { if err != nil { t.Error(err) } - time.Sleep(time.Second) + pinDelay() // check that it is held by exactly nClusters -1 peers gpi, err := clusters[j].Status(h) @@ -814,7 +856,7 @@ func TestClustersReplication(t *testing.T) { if numRemote != 1 { t.Errorf("We wanted 1 peer track as remote but %d do", numRemote) } - time.Sleep(time.Second) // this is for metric to be up to date + ttlDelay() } f := func(t *testing.T, c *Cluster) { @@ -875,13 +917,15 @@ func TestClustersReplicationFactorMax(t *testing.T) { c.config.ReplicationFactorMax = nClusters - 1 } + ttlDelay() + h, _ := cid.Decode(test.TestCid1) err := clusters[0].Pin(api.PinCid(h)) if err != nil { t.Fatal(err) } - delay() + pinDelay() f := func(t *testing.T, c *Cluster) { p, err := c.PinGet(h) @@ -918,13 +962,15 @@ func TestClustersReplicationFactorMaxLower(t *testing.T) { c.config.ReplicationFactorMax = nClusters } + ttlDelay() // make sure we have places to pin + h, _ := cid.Decode(test.TestCid1) err := clusters[0].Pin(api.PinCid(h)) if err != nil { t.Fatal(err) } - delay() + pinDelay() p1, err := clusters[0].PinGet(h) if err != nil { @@ -944,7 +990,7 @@ func TestClustersReplicationFactorMaxLower(t *testing.T) { t.Fatal(err) } - delay() + pinDelay() p2, err := clusters[0].PinGet(h) if err != nil { @@ -970,24 +1016,21 @@ func TestClustersReplicationFactorInBetween(t *testing.T) { c.config.ReplicationFactorMax = nClusters } + ttlDelay() + // Shutdown two peers clusters[nClusters-1].Shutdown() clusters[nClusters-2].Shutdown() - time.Sleep(time.Second) // let metric expire - waitForLeader(t, clusters) - // allow metrics to arrive to new leader - delay() - h, _ := cid.Decode(test.TestCid1) err := clusters[0].Pin(api.PinCid(h)) if err != nil { t.Fatal(err) } - delay() + pinDelay() f := func(t *testing.T, c *Cluster) { if c == clusters[nClusters-1] || c == clusters[nClusters-2] { @@ -1029,15 +1072,10 @@ func TestClustersReplicationFactorMin(t *testing.T) { // Shutdown two peers clusters[nClusters-1].Shutdown() + waitForLeader(t, clusters) clusters[nClusters-2].Shutdown() - - time.Sleep(time.Second) // let metric expire - waitForLeader(t, clusters) - // allow metrics to arrive to new leader - delay() - h, _ := cid.Decode(test.TestCid1) err := clusters[0].Pin(api.PinCid(h)) if err == nil { @@ -1063,28 +1101,29 @@ func TestClustersReplicationMinMaxNoRealloc(t *testing.T) { c.config.ReplicationFactorMax = nClusters } + ttlDelay() + h, _ := cid.Decode(test.TestCid1) err := clusters[0].Pin(api.PinCid(h)) if err != nil { t.Fatal(err) } + pinDelay() + // Shutdown two peers clusters[nClusters-1].Shutdown() + waitForLeader(t, clusters) clusters[nClusters-2].Shutdown() - - time.Sleep(time.Second) // let metric expire - waitForLeader(t, clusters) - // allow metrics to arrive to new leader - delay() - err = clusters[0].Pin(api.PinCid(h)) if err != nil { t.Fatal(err) } + pinDelay() + p, err := clusters[0].PinGet(h) if err != nil { t.Fatal(err) @@ -1114,13 +1153,15 @@ func TestClustersReplicationMinMaxRealloc(t *testing.T) { c.config.ReplicationFactorMax = 4 } + ttlDelay() // make sure metrics are in + h, _ := cid.Decode(test.TestCid1) err := clusters[0].Pin(api.PinCid(h)) if err != nil { t.Fatal(err) } - delay() + pinDelay() p, err := clusters[0].PinGet(h) if err != nil { @@ -1142,19 +1183,16 @@ func TestClustersReplicationMinMaxRealloc(t *testing.T) { alloc1.Shutdown() alloc2.Shutdown() - time.Sleep(time.Second) // let metric expire - waitForLeader(t, clusters) - // allow metrics to arrive to new leader - delay() - // Repin - (although this might have been taken of if there was an alert err = safePeer.Pin(api.PinCid(h)) if err != nil { t.Fatal(err) } + pinDelay() + p, err = safePeer.PinGet(h) if err != nil { t.Fatal(err) @@ -1176,7 +1214,7 @@ func TestClustersReplicationMinMaxRealloc(t *testing.T) { lenSA := len(secondAllocations) expected := minInt(nClusters-2, 4) if lenSA != expected { - t.Errorf("Inssufficient reallocation, could have allocated to %d peers but instead only allocated to %d peers", expected, lenSA) + t.Errorf("Insufficient reallocation, could have allocated to %d peers but instead only allocated to %d peers", expected, lenSA) } if lenSA < 3 { @@ -1194,6 +1232,8 @@ func TestClustersReplicationRealloc(t *testing.T) { c.config.ReplicationFactorMax = nClusters - 1 } + ttlDelay() + j := rand.Intn(nClusters) h, _ := cid.Decode(test.TestCid1) err := clusters[j].Pin(api.PinCid(h)) @@ -1202,7 +1242,7 @@ func TestClustersReplicationRealloc(t *testing.T) { } // Let the pin arrive - time.Sleep(time.Second / 2) + pinDelay() pin := clusters[j].Pins()[0] pinSerial := pin.ToSerial() @@ -1217,7 +1257,7 @@ func TestClustersReplicationRealloc(t *testing.T) { t.Fatal(err) } - time.Sleep(time.Second / 2) + pinDelay() pin2 := clusters[j].Pins()[0] pinSerial2 := pin2.ToSerial() @@ -1245,10 +1285,7 @@ func TestClustersReplicationRealloc(t *testing.T) { // let metrics expire and give time for the cluster to // see if they have lost the leader - time.Sleep(4 * time.Second) waitForLeader(t, clusters) - // wait for new metrics to arrive - time.Sleep(2 * time.Second) // Make sure we haven't killed our randomly // selected cluster @@ -1262,7 +1299,7 @@ func TestClustersReplicationRealloc(t *testing.T) { t.Fatal(err) } - time.Sleep(time.Second / 2) + pinDelay() numPinned := 0 for i, c := range clusters { @@ -1303,12 +1340,11 @@ func TestClustersReplicationNotEnoughPeers(t *testing.T) { } // Let the pin arrive - time.Sleep(time.Second / 2) + pinDelay() clusters[0].Shutdown() clusters[1].Shutdown() - delay() waitForLeader(t, clusters) err = clusters[2].Pin(api.PinCid(h)) @@ -1337,7 +1373,7 @@ func TestClustersRebalanceOnPeerDown(t *testing.T) { // pin something h, _ := cid.Decode(test.TestCid1) clusters[0].Pin(api.PinCid(h)) - time.Sleep(time.Second * 2) // let the pin arrive + pinDelay() pinLocal := 0 pinRemote := 0 var localPinner peer.ID @@ -1361,7 +1397,7 @@ func TestClustersRebalanceOnPeerDown(t *testing.T) { t.Fatal("Not pinned as expected") } - // find a kill the local pinner + // kill the local pinner for _, c := range clusters { if c.id == localPinner { c.Shutdown() @@ -1370,8 +1406,8 @@ func TestClustersRebalanceOnPeerDown(t *testing.T) { } } - // Sleep a monitoring interval - time.Sleep(6 * time.Second) + delay() + waitForLeader(t, clusters) // incase we killed the leader // It should be now pinned in the remote pinner if s := remotePinnerCluster.tracker.Status(h).Status; s != api.TrackerStatusPinned { @@ -1452,8 +1488,6 @@ func validateClusterGraph(t *testing.T, graph api.ConnectGraph, clusterIDs map[p func TestClustersGraphConnected(t *testing.T) { clusters, mock := createClusters(t) defer shutdownClusters(t, clusters, mock) - delay() - delay() j := rand.Intn(nClusters) // choose a random cluster peer to query graph, err := clusters[j].ConnectGraph() @@ -1496,9 +1530,8 @@ func TestClustersGraphUnhealthy(t *testing.T) { clusters[discon1].Shutdown() clusters[discon2].Shutdown() - delay() + waitForLeader(t, clusters) - delay() graph, err := clusters[j].ConnectGraph() if err != nil { diff --git a/monitor/basic/peer_monitor.go b/monitor/basic/peer_monitor.go index 1ed3fd5f3..341c76599 100644 --- a/monitor/basic/peer_monitor.go +++ b/monitor/basic/peer_monitor.go @@ -22,7 +22,7 @@ var logger = logging.Logger("monitor") var AlertChannelCap = 256 // WindowCap specifies how many metrics to keep for given host and metric type -var WindowCap = 10 +var WindowCap = 100 // peerMetrics is just a circular queue type peerMetrics struct { @@ -55,6 +55,7 @@ func (pmets *peerMetrics) latest() (api.Metric, error) { // pmets.mux.RLock() // defer pmets.mux.RUnlock() if len(pmets.window) == 0 { + logger.Warning("no metrics") return api.Metric{}, errors.New("no metrics") } return pmets.window[pmets.last], nil diff --git a/peer_manager_test.go b/peer_manager_test.go index e420437d5..d3a868ec9 100644 --- a/peer_manager_test.go +++ b/peer_manager_test.go @@ -29,7 +29,6 @@ func peerManagerClusters(t *testing.T) ([]*Cluster, []*test.IpfsMock) { }(i) } wg.Wait() - delay() return cls, mocks } @@ -66,7 +65,7 @@ func TestClustersPeerAdd(t *testing.T) { if err != nil { t.Fatal(err) } - delay() + pinDelay() f := func(t *testing.T, c *Cluster) { ids := c.Peers() @@ -89,8 +88,6 @@ func TestClustersPeerAdd(t *testing.T) { t.Error("By now cluster peers should reflect all peers") } - time.Sleep(2 * time.Second) - // check that they are part of the configuration // This only works because each peer only has one multiaddress // (localhost) @@ -215,6 +212,7 @@ func TestClustersPeerRemoveSelf(t *testing.T) { defer shutdownClusters(t, clusters, mocks) for i := 0; i < len(clusters); i++ { + waitForLeader(t, clusters) peers := clusters[i].Peers() t.Logf("Current cluster size: %d", len(peers)) if len(peers) != (len(clusters) - i) { @@ -287,7 +285,7 @@ func TestClustersPeerRemoveLeader(t *testing.T) { if more { t.Error("should be done") } - time.Sleep(time.Second) + time.Sleep(time.Second / 2) } } @@ -342,10 +340,10 @@ func TestClustersPeerRemoveReallocsPins(t *testing.T) { checkErr(t, err) err = leader.Pin(api.PinCid(h)) checkErr(t, err) - time.Sleep(time.Second) // time to update the metrics + ttlDelay() } - delay() + pinDelay() // At this point, all peers must have 1 pin associated to them. // Find out which pin is associated to leader. @@ -374,9 +372,7 @@ func TestClustersPeerRemoveReallocsPins(t *testing.T) { t.Fatal("error removing peer:", err) } - time.Sleep(2 * time.Second) waitForLeader(t, clusters) - delay() for _, icid := range interestingCids { // Now check that the allocations are new. @@ -406,7 +402,7 @@ func TestClustersPeerJoin(t *testing.T) { } hash, _ := cid.Decode(test.TestCid1) clusters[0].Pin(api.PinCid(hash)) - delay() + pinDelay() f := func(t *testing.T, c *Cluster) { peers := c.Peers() @@ -439,7 +435,7 @@ func TestClustersPeerJoinAllAtOnce(t *testing.T) { hash, _ := cid.Decode(test.TestCid1) clusters[0].Pin(api.PinCid(hash)) - delay() + pinDelay() f2 := func(t *testing.T, c *Cluster) { peers := c.Peers() @@ -556,7 +552,7 @@ func TestClustersPeerRejoin(t *testing.T) { t.Fatal(err) } - delay() + pinDelay() // Rejoin c0 c0, m0 := createOnePeerCluster(t, 0, testingClusterSecret) diff --git a/pnet_test.go b/pnet_test.go index dbf7b5e06..fb803f638 100644 --- a/pnet_test.go +++ b/pnet_test.go @@ -53,28 +53,29 @@ func TestSimplePNet(t *testing.T) { } } -func TestClusterSecretRequired(t *testing.T) { - cl1Secret, err := generateClusterSecret() - if err != nil { - t.Fatal("Unable to generate cluster secret.") - } - cl1, _ := createOnePeerCluster(t, 1, cl1Secret) - cl2, _ := createOnePeerCluster(t, 2, testingClusterSecret) - defer cleanRaft() - defer cl1.Shutdown() - defer cl2.Shutdown() - peers1 := cl1.Peers() - peers2 := cl2.Peers() +// Adds one minute to tests. Disabled for the moment. +// func TestClusterSecretRequired(t *testing.T) { +// cl1Secret, err := generateClusterSecret() +// if err != nil { +// t.Fatal("Unable to generate cluster secret.") +// } +// cl1, _ := createOnePeerCluster(t, 1, cl1Secret) +// cl2, _ := createOnePeerCluster(t, 2, testingClusterSecret) +// defer cleanRaft() +// defer cl1.Shutdown() +// defer cl2.Shutdown() +// peers1 := cl1.Peers() +// peers2 := cl2.Peers() - _, err = cl1.PeerAdd(clusterAddr(cl2)) - if err == nil { - t.Fatal("Peer entered private cluster without key.") - } +// _, err = cl1.PeerAdd(clusterAddr(cl2)) +// if err == nil { +// t.Fatal("Peer entered private cluster without key.") +// } - if len(peers1) != len(peers2) { - t.Fatal("Expected same number of peers") - } - if len(peers1) != 1 { - t.Fatal("Expected no peers other than self") - } -} +// if len(peers1) != len(peers2) { +// t.Fatal("Expected same number of peers") +// } +// if len(peers1) != 1 { +// t.Fatal("Expected no peers other than self") +// } +// }