From 3bfa01c5e6c994160ff775e608ce5f06154e078c Mon Sep 17 00:00:00 2001 From: Peter Schroeter Date: Mon, 22 Jun 2015 21:50:44 -0700 Subject: [PATCH] IV-2077 Bit more idiomatic go --- Makefile | 2 +- tunnel/wstuncli.go | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 9bac217..7852f39 100644 --- a/Makefile +++ b/Makefile @@ -130,6 +130,6 @@ travis-test: lint # that if there are errors the output of gingko refers to incorrect line numbers # tip: if you don't like colors use ginkgo -r -noColor test: lint - ginkgo -r -v + ginkgo -r ginkgo -r -cover go tool cover -func=`basename $$PWD`.coverprofile diff --git a/tunnel/wstuncli.go b/tunnel/wstuncli.go index 99b08b3..b4b1578 100644 --- a/tunnel/wstuncli.go +++ b/tunnel/wstuncli.go @@ -201,9 +201,9 @@ func (t *WSTunnelClient) Start() error { // for test purposes we have a signal that tells wstuncli to exit instead of reopening // a fresh connection. We also block and wait for the initial WS connection to occur // (or fail). This is also for test purposes, as we run into a race condition - // where the server tries to connect to the client before it can set up the connection. + // where we make requests to the server before the client connection is ready. t.exitChan = make(chan struct{}, 1) - waitForConn := sync.NewCond(new(sync.Mutex)) + waitForConn := make(chan struct{}, 1) //===== Goroutine ===== @@ -223,7 +223,10 @@ func (t *WSTunnelClient) Start() error { var err error var resp *http.Response t.ws, resp, err = d.Dial(url, h) - waitForConn.Signal() + select { + case waitForConn <- struct{}{}: + default: + } if err != nil { extra := "" if resp != nil { @@ -259,9 +262,7 @@ func (t *WSTunnelClient) Start() error { } }() - waitForConn.L.Lock() - waitForConn.Wait() - waitForConn.L.Unlock() + <-waitForConn return nil }