Skip to content

Commit

Permalink
Enable E2E test running on Travis CI
Browse files Browse the repository at this point in the history
- We want Travis build to fail if E2E tests fail.
- Renamed "perf-test" makefile target to "e2e-test" (since these
  are not just perf tests but also other types of end-to-end tests).
- Fix TestGeneratorAndBackend to make sure it waits properly for
  the generator to produce results.

Issue: open-telemetry#68
  • Loading branch information
Tigran Najaryan committed Jun 28, 2019
1 parent f28c6b8 commit e5d8376
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 9 deletions.
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,17 @@ all-srcs:
.PHONY: fmt-vet-lint-test
fmt-vet-lint-test: fmt vet lint test

.PHONY: perf-test
perf-test: otelsvc
.PHONY: e2e-test
e2e-test: otelsvc
$(MAKE) -C testbed runtests

.PHONY: test
test:
$(GOTEST) $(GOTEST_OPT) $(ALL_PKGS)

.PHONY: travis-ci
travis-ci: fmt vet lint test-with-cover
travis-ci: fmt vet lint test-with-cover otelsvc
$(MAKE) -C testbed runtests

.PHONY: test-with-cover
test-with-cover:
Expand Down
1 change: 1 addition & 0 deletions testbed/testbed/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mockbackend.log
4 changes: 4 additions & 0 deletions testbed/testbed/load_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ func (lg *LoadGenerator) GetStats() string {
return fmt.Sprintf("Sent:%5d spans", atomic.LoadUint64(&lg.SpansSent))
}

func (lg *LoadGenerator) GetSpansSent() uint64 {
return atomic.LoadUint64(&lg.SpansSent)
}

func (lg *LoadGenerator) generate() {
// Indicate that generation is done at the end
defer lg.stopWait.Done()
Expand Down
37 changes: 31 additions & 6 deletions testbed/testbed/mock_backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,42 @@ func TestGeneratorAndBackend(t *testing.T) {

assert.EqualValues(t, 0, lg.SpansSent)

// Generate for about 10ms at 1000 SPS
// Generate at 1000 SPS
lg.Start(LoadOptions{SpansPerSecond: 1000})

time.Sleep(time.Millisecond * 10)
// Wait until at least 50 spans are sent
WaitFor(t, func() bool { return lg.GetSpansSent() > 50 }, "SpansSent > 50")

lg.Stop()

// Presumably should have generated something. If not then the testbed is very slow
// so we will consider it a failure.
assert.True(t, lg.SpansSent > 0)

// The backend should receive everything generated.
assert.Equal(t, lg.SpansSent, mb.SpansReceived())
}

// WaitFor the specific condition for up to 5 seconds. Records a test error
// if condition does not become true.
func WaitFor(t *testing.T, cond func() bool, errMsg ...interface{}) bool {
startTime := time.Now()

// Start with 5 ms waiting interval between condition re-evaluation.
waitInterval := time.Millisecond * 5

for {
time.Sleep(waitInterval)

// Increase waiting interval exponentially up to 500 ms.
if waitInterval < time.Millisecond*500 {
waitInterval = waitInterval * 2
}

if cond() {
return true
}

if time.Since(startTime) > time.Second*5 {
// Waited too long
t.Error("Time out waiting for", errMsg)
return false
}
}
}
1 change: 1 addition & 0 deletions testbed/tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
results/*

0 comments on commit e5d8376

Please sign in to comment.