From 222a935b40dfda34a8c8e1570dcfd4dd98f6eb13 Mon Sep 17 00:00:00 2001 From: Noah Watkins Date: Sat, 30 Aug 2014 10:33:09 -0700 Subject: [PATCH] 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 --- rados_test.go | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/rados_test.go b/rados_test.go index 9eb329c..bcae5fe 100644 --- a/rados_test.go +++ b/rados_test.go @@ -74,12 +74,35 @@ func TestGetClusterStats(t *testing.T) { conn.ReadDefaultConfigFile() conn.Connect() - stat, err := conn.GetClusterStats() + poolname := GetUUID() + err := conn.MakePool(poolname) assert.NoError(t, err) - assert.True(t, stat.Kb > 0) - assert.True(t, stat.Kb_used > 0) - assert.True(t, stat.Kb_avail > 0) - assert.True(t, stat.Num_objects > 0) + + 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() + 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) {