From 08b8dd796a9d5ac95ca4afc293bd3c3ed2d0a85a Mon Sep 17 00:00:00 2001 From: Ivan Kozlovic Date: Mon, 8 Feb 2016 15:51:41 -0700 Subject: [PATCH] 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. --- server/monitor_test.go | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/server/monitor_test.go b/server/monitor_test.go index eb141ad8..6194614b 100644 --- a/server/monitor_test.go +++ b/server/monitor_test.go @@ -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) } }