Skip to content

Commit

Permalink
Fix #339: Reduce Sleeps in tests
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Hector Sanjuan <code@hector.link>
  • Loading branch information
hsanjuan committed Mar 20, 2018
1 parent a357b76 commit 4fd234b
Show file tree
Hide file tree
Showing 9 changed files with 170 additions and 136 deletions.
3 changes: 1 addition & 2 deletions cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -291,7 +290,7 @@ func (c *Cluster) pushInformerMetrics() {
retries++
}
// retry in retryDelay
timer.Reset(retryDelay)
timer.Reset(metric.GetTTL() / 4)
continue
}

Expand Down
2 changes: 1 addition & 1 deletion cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 13 additions & 12 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(`{
Expand Down Expand Up @@ -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"
}`)

Expand Down
2 changes: 2 additions & 0 deletions consensus/raft/consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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)
Expand Down
Loading

0 comments on commit 4fd234b

Please sign in to comment.