Fix test to check Idle instead of relying on client id.

Since client connections are handled in go routines, we don't have a guarantee that the second client's id will be > than the first.
This commit is contained in:
Ivan Kozlovic
2016-02-08 15:51:41 -07:00
parent ecec51a771
commit 08b8dd796a

View File

@@ -837,11 +837,8 @@ func TestConnzSortedByIdle(t *testing.T) {
secondClient.Subscribe("client.2", func(m *nats.Msg) {})
secondClient.Flush()
// The Idle granularity is a whole second, that being said,
// the value used to do the sort is in nano. So we will update
// the first client, and check that the sort returns the second
// client having the "highest" idle time. We will use cid's to
// verify that.
// The Idle granularity is a whole second
time.Sleep(time.Second)
firstClient.Publish("client.1", []byte("new message"))
url := fmt.Sprintf("http://localhost:%d/", MONITOR_PORT)
@@ -873,25 +870,18 @@ func TestConnzSortedByIdle(t *testing.T) {
t.Fatal("Expected Idle value to be valid")
}
// If we are willing to sleep a whole second before sending a message
// to the first client, we could enable this code.
/*
idle1, err := time.ParseDuration(c.Conns[0].Idle)
if err != nil {
t.Fatalf("Unable to parse duration %v, err=%v", c.Conns[0].Idle, err)
}
idle2, err := time.ParseDuration(c.Conns[1].Idle)
if err != nil {
t.Fatalf("Unable to parse duration %v, err=%v", c.Conns[0].Idle, err)
}
idle1, err := time.ParseDuration(c.Conns[0].Idle)
if err != nil {
t.Fatalf("Unable to parse duration %v, err=%v", c.Conns[0].Idle, err)
}
idle2, err := time.ParseDuration(c.Conns[1].Idle)
if err != nil {
t.Fatalf("Unable to parse duration %v, err=%v", c.Conns[0].Idle, err)
}
if idle1 < idle2 {
t.Fatalf("Expected conns sorted in descending order by Idle, got %v < %v\n",
idle1, idle2)
}
*/
if c.Conns[0].Cid < c.Conns[1].Cid {
t.Fatalf("Expected second client to be more idle than first")
if idle1 < idle2 {
t.Fatalf("Expected conns sorted in descending order by Idle, got %v < %v\n",
idle1, idle2)
}
}