Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1769 from weaveworks/ditch-run-with-timeout
Browse files Browse the repository at this point in the history
Wins the prize for "best add-to-delete ratio in a PR this year"
  • Loading branch information
bboreham committed Dec 9, 2015
2 parents 0ef57a1 + 1374e4c commit 9bf18b1
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 40 deletions.
7 changes: 0 additions & 7 deletions ipam/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/stretchr/testify/require"
"github.com/weaveworks/weave/common"
"github.com/weaveworks/weave/net/address"
wt "github.com/weaveworks/weave/testing"
)

func HTTPPost(t *testing.T, url string) string {
Expand Down Expand Up @@ -145,12 +144,6 @@ func TestBadHttp(t *testing.T) {
}

func TestHTTPCancel(t *testing.T) {
wt.RunWithTimeout(t, 2*time.Second, func() {
impTestHTTPCancel(t)
})
}

func impTestHTTPCancel(t *testing.T) {
var (
containerID = "deadbeef"
testCIDR1 = "10.0.3.0/29"
Expand Down
10 changes: 1 addition & 9 deletions mesh/gossip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import (
"fmt"
"sync"
"testing"
"time"

"github.com/stretchr/testify/require"
wt "github.com/weaveworks/weave/testing"
)

// TODO test gossip unicast; atm we only test topology gossip and
Expand Down Expand Up @@ -67,12 +65,6 @@ func (router *Router) DeleteTestChannelConnection(r *Router) {
router.Ourself.handleDeleteConnection(conn)
}

func TestGossipTopology(t *testing.T) {
wt.RunWithTimeout(t, 5*time.Second, func() {
implTestGossipTopology(t)
})
}

// Create a Peer representing the receiver router, with connections to
// the routers supplied as arguments, carrying across all UID and
// version information.
Expand All @@ -95,7 +87,7 @@ func checkTopology(t *testing.T, router *Router, wantedPeers ...*Peer) {
router.Peers.RUnlock()
}

func implTestGossipTopology(t *testing.T) {
func TestGossipTopology(t *testing.T) {
// Create some peers that will talk to each other
r1 := NewTestRouter("01:00:00:01:00:00")
r2 := NewTestRouter("02:00:00:02:00:00")
Expand Down
7 changes: 0 additions & 7 deletions nameserver/nameserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

"github.com/weaveworks/weave/mesh"
"github.com/weaveworks/weave/net/address"
wt "github.com/weaveworks/weave/testing"
"github.com/weaveworks/weave/testing/gossip"
)

Expand Down Expand Up @@ -76,12 +75,6 @@ func (m mapping) Addrs() []address.Address {
}

func TestNameservers(t *testing.T) {
wt.RunWithTimeout(t, 2*time.Minute, func() {
testNameservers(t)
})
}

func testNameservers(t *testing.T) {
//common.SetLogLevel("debug")

lookupTimeout := 10 // ms
Expand Down
17 changes: 0 additions & 17 deletions testing/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"reflect"
"runtime"
"testing"
"time"

"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -36,22 +35,6 @@ func stackTrace(all bool) string {
return string(buf[:stacklen])
}

// Borrowed from net/http tests:
// goTimeout runs f, failing t if f takes more than d to complete.
func RunWithTimeout(t *testing.T, d time.Duration, f func()) {
ch := make(chan bool, 2)
timer := time.AfterFunc(d, func() {
t.Errorf("Timeout expired after %v: stacks:\n%s", d, stackTrace(true))
ch <- true
})
defer timer.Stop()
go func() {
defer func() { ch <- true }()
f()
}()
<-ch
}

// TrimTestArgs finds the first -- in os.Args and trim all args before that
func TrimTestArgs() {
i, l := 0, len(os.Args)
Expand Down

0 comments on commit 9bf18b1

Please sign in to comment.