go: fix timing issue in ring test
Change-Id: Id555f69f74f786e4a8c61fd64d8dc4ba9cbbba39
This commit is contained in:
parent
63acd4d0a4
commit
021740a0ae
@ -18,7 +18,6 @@ package hummingbird
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
@ -177,7 +176,6 @@ func TestGetLoad(t *testing.T) {
|
||||
var v map[string]interface{}
|
||||
err := json.Unmarshal(output, &v)
|
||||
require.Nil(t, err)
|
||||
fmt.Println(v)
|
||||
m5, ok := v["5m"]
|
||||
require.True(t, ok)
|
||||
m5f, ok := m5.(float64)
|
||||
|
@ -68,6 +68,8 @@ func writeARing(w io.Writer, deviceCount int, replicaCount int, partShift uint)
|
||||
func TestLoadRing(t *testing.T) {
|
||||
fp, err := ioutil.TempFile("", "")
|
||||
require.Nil(t, err)
|
||||
defer fp.Close()
|
||||
defer os.RemoveAll(fp.Name())
|
||||
require.Nil(t, writeARing(fp, 4, 2, 29))
|
||||
r, err := LoadRing(fp.Name(), "prefix", "suffix")
|
||||
require.Nil(t, err)
|
||||
@ -82,6 +84,8 @@ func TestLoadRing(t *testing.T) {
|
||||
func TestGetNodes(t *testing.T) {
|
||||
fp, err := ioutil.TempFile("", "")
|
||||
require.Nil(t, err)
|
||||
defer fp.Close()
|
||||
defer os.RemoveAll(fp.Name())
|
||||
require.Nil(t, writeARing(fp, 4, 2, 29))
|
||||
r, err := LoadRing(fp.Name(), "prefix", "suffix")
|
||||
require.Nil(t, err)
|
||||
@ -98,6 +102,8 @@ func TestGetNodes(t *testing.T) {
|
||||
func TestGetJobNodes(t *testing.T) {
|
||||
fp, err := ioutil.TempFile("", "")
|
||||
require.Nil(t, err)
|
||||
defer fp.Close()
|
||||
defer os.RemoveAll(fp.Name())
|
||||
require.Nil(t, writeARing(fp, 4, 2, 29))
|
||||
r, err := LoadRing(fp.Name(), "prefix", "suffix")
|
||||
require.Nil(t, err)
|
||||
@ -116,6 +122,8 @@ func TestGetJobNodes(t *testing.T) {
|
||||
func TestRingReload(t *testing.T) {
|
||||
fp, err := ioutil.TempFile("", "")
|
||||
require.Nil(t, err)
|
||||
defer fp.Close()
|
||||
defer os.RemoveAll(fp.Name())
|
||||
require.Nil(t, writeARing(fp, 4, 2, 29))
|
||||
r, err := LoadRing(fp.Name(), "prefix", "suffix")
|
||||
require.Nil(t, err)
|
||||
@ -125,13 +133,8 @@ func TestRingReload(t *testing.T) {
|
||||
fp.Seek(0, os.SEEK_SET)
|
||||
fp.Truncate(0)
|
||||
require.Nil(t, writeARing(fp, 5, 3, 30))
|
||||
ring.reload()
|
||||
// the values shouldn't change if reload is called immediately
|
||||
require.Equal(t, 4, len(ring.getData().Devs))
|
||||
require.Equal(t, 2, ring.getData().ReplicaCount)
|
||||
require.Equal(t, uint64(29), ring.getData().PartShift)
|
||||
// simulate some time having passed
|
||||
ring.mtime = time.Now().Add(time.Second * -20)
|
||||
// make sure the mtime has changed
|
||||
os.Chtimes(fp.Name(), time.Now(), time.Now().Add(time.Second))
|
||||
ring.reload()
|
||||
require.Equal(t, 5, len(ring.getData().Devs))
|
||||
require.Equal(t, 3, ring.getData().ReplicaCount)
|
||||
|
Loading…
x
Reference in New Issue
Block a user