From b394dff38f383da666fba9e4fe48b90032d2a1f5 Mon Sep 17 00:00:00 2001 From: Ryan Uber Date: Thu, 16 Oct 2014 10:14:36 -0700 Subject: [PATCH] agent: optimize rpc monitor test --- command/agent/rpc_client_test.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/command/agent/rpc_client_test.go b/command/agent/rpc_client_test.go index 4e6f09252..18825613c 100644 --- a/command/agent/rpc_client_test.go +++ b/command/agent/rpc_client_test.go @@ -232,7 +232,7 @@ func TestRPCClientMonitor(t *testing.T) { found := false OUTER1: - for { + for i := 0; ; i++ { select { case e := <-eventCh: if strings.Contains(e, "Accepted client") { @@ -240,6 +240,10 @@ OUTER1: break OUTER1 } default: + if i > 100 { + break OUTER1 + } + time.Sleep(10 * time.Millisecond) } } if !found { @@ -249,18 +253,20 @@ OUTER1: // Join a bad thing to generate more events p1.agent.JoinLAN(nil) - time.Sleep(1 * time.Second) - found = false OUTER2: - for { + for i := 0; ; i++ { select { case e := <-eventCh: if strings.Contains(e, "joining") { found = true + break OUTER2 } default: - break OUTER2 + if i > 100 { + break OUTER2 + } + time.Sleep(10 * time.Millisecond) } } if !found {