mirror of
https://github.com/weaveworks/scope.git
synced 2026-03-03 02:00:43 +00:00
Merge pull request #307 from weaveworks/303-test-cpu
Add -cpu 4 to tests.
This commit is contained in:
6
bin/test
6
bin/test
@@ -2,10 +2,10 @@
|
||||
|
||||
set -eu
|
||||
|
||||
GO_TEST_ARGS=""
|
||||
GO_TEST_ARGS="-cpu 4 -timeout 10s -tags netgo"
|
||||
SLOW=""
|
||||
if [ $# -eq 1 ] && [ "$1" = "-slow" ]; then
|
||||
GO_TEST_ARGS="-race -covermode=atomic"
|
||||
GO_TEST_ARGS="$GO_TEST_ARGS -race -covermode=atomic"
|
||||
SLOW="yes"
|
||||
fi
|
||||
|
||||
@@ -26,7 +26,7 @@ for dir in $(find . -type f -name '*_test.go' | grep -v '^./.git/' | grep -v '^
|
||||
GO_TEST_ARGS_RUN="$GO_TEST_ARGS"
|
||||
fi
|
||||
|
||||
if ! go test $GO_TEST_ARGS_RUN -timeout 10s -tags netgo $dir ; then
|
||||
if ! go test $GO_TEST_ARGS_RUN $dir ; then
|
||||
fail=1
|
||||
fi
|
||||
|
||||
|
||||
@@ -8,9 +8,12 @@ import (
|
||||
"net/http"
|
||||
"runtime"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
client "github.com/fsouza/go-dockerclient"
|
||||
|
||||
"github.com/weaveworks/scope/probe/docker"
|
||||
"github.com/weaveworks/scope/test"
|
||||
)
|
||||
|
||||
type mockConnection struct {
|
||||
@@ -56,11 +59,10 @@ func TestContainer(t *testing.T) {
|
||||
if err = json.NewEncoder(writer).Encode(&stats); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
runtime.Gosched() // wait for StartGatheringStats goroutine to receive the stats
|
||||
|
||||
// Now see if we go them
|
||||
nmd := c.GetNodeMetadata()
|
||||
if nmd[docker.MemoryUsage] != "12345" {
|
||||
t.Errorf("want 12345, got %s", nmd[docker.MemoryUsage])
|
||||
}
|
||||
test.Poll(t, 10*time.Millisecond, func() bool {
|
||||
nmd := c.GetNodeMetadata()
|
||||
return nmd[docker.MemoryUsage] == "12345"
|
||||
}, "Failed to get stats")
|
||||
}
|
||||
|
||||
@@ -160,13 +160,11 @@ func TestRegistry(t *testing.T) {
|
||||
defer registry.Stop()
|
||||
runtime.Gosched()
|
||||
|
||||
{
|
||||
test.Poll(t, 10*time.Millisecond, func() bool {
|
||||
have := allContainers(registry)
|
||||
want := []docker.Container{&mockContainer{container1}}
|
||||
if !reflect.DeepEqual(want, have) {
|
||||
t.Errorf("%s", test.Diff(want, have))
|
||||
}
|
||||
}
|
||||
return reflect.DeepEqual(want, have)
|
||||
}, "Didn't get containers!")
|
||||
|
||||
{
|
||||
have := allImages(registry)
|
||||
|
||||
20
test/poll.go
Normal file
20
test/poll.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Poll repeatedly evaluates condition until we either timeout, or it suceeds.
|
||||
func Poll(t *testing.T, d time.Duration, condition func() bool, msg string) {
|
||||
deadline := time.Now().Add(d)
|
||||
for {
|
||||
if time.Now().After(deadline) {
|
||||
t.Fatal(msg)
|
||||
}
|
||||
if condition() {
|
||||
return
|
||||
}
|
||||
time.Sleep(d / 10)
|
||||
}
|
||||
}
|
||||
@@ -53,7 +53,7 @@ func TestCollector(t *testing.T) {
|
||||
}
|
||||
|
||||
reports <- r
|
||||
poll(t, 100*time.Millisecond, func() bool {
|
||||
test.Poll(t, 100*time.Millisecond, func() bool {
|
||||
return len(concreteCollector.peek().Address.NodeMetadatas) == 1
|
||||
}, "missed the report")
|
||||
|
||||
@@ -101,16 +101,3 @@ func testPublisher(t *testing.T, input <-chan interface{}) net.Listener {
|
||||
}()
|
||||
return ln
|
||||
}
|
||||
|
||||
func poll(t *testing.T, d time.Duration, condition func() bool, msg string) {
|
||||
deadline := time.Now().Add(d)
|
||||
for {
|
||||
if time.Now().After(deadline) {
|
||||
t.Fatal(msg)
|
||||
}
|
||||
if condition() {
|
||||
return
|
||||
}
|
||||
time.Sleep(d / 10)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user