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()
poolname := GetUUID()
err := conn.MakePool(poolname)
assert.NoError(t, err)
pool, err := conn.OpenPool(poolname)
assert.NoError(t, err)
buf := make([]byte, 1<<22)
pool.Write("obj", buf, 0)
for i := 0; i < 30; i++ {
stat, err := conn.GetClusterStats() stat, err := conn.GetClusterStats()
assert.NoError(t, err) assert.NoError(t, err)
assert.True(t, stat.Kb > 0)
assert.True(t, stat.Kb_used > 0) // wait a second if stats are zero
assert.True(t, stat.Kb_avail > 0) if stat.Kb == 0 || stat.Kb_used == 0 ||
assert.True(t, stat.Num_objects > 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) {