test: add data to cluster before stat

For an empty cluster we need to write data into the cluster so cluster
stats come back as non-zero. This also adds a max 30 second delay to
wait for the stats to update.

Signed-off-by: Noah Watkins <noahwatkins@gmail.com>
This commit is contained in:
Noah Watkins 2014-08-30 10:33:09 -07:00
parent b8609f826c
commit 222a935b40
1 changed files with 28 additions and 5 deletions

View File

@ -74,12 +74,35 @@ func TestGetClusterStats(t *testing.T) {
conn.ReadDefaultConfigFile() conn.ReadDefaultConfigFile()
conn.Connect() conn.Connect()
stat, err := conn.GetClusterStats() poolname := GetUUID()
err := conn.MakePool(poolname)
assert.NoError(t, err) assert.NoError(t, err)
assert.True(t, stat.Kb > 0)
assert.True(t, stat.Kb_used > 0) pool, err := conn.OpenPool(poolname)
assert.True(t, stat.Kb_avail > 0) assert.NoError(t, err)
assert.True(t, stat.Num_objects > 0)
buf := make([]byte, 1<<22)
pool.Write("obj", buf, 0)
for i := 0; i < 30; i++ {
stat, err := conn.GetClusterStats()
assert.NoError(t, err)
// wait a second if stats are zero
if stat.Kb == 0 || stat.Kb_used == 0 ||
stat.Kb_avail == 0 || stat.Num_objects == 0 {
fmt.Println("waiting for cluster stats to refresh")
time.Sleep(time.Second)
} else {
// success
conn.Shutdown()
return
}
}
t.Error("Cluster stats are zero")
conn.Shutdown()
} }
func TestGetFSID(t *testing.T) { func TestGetFSID(t *testing.T) {