Skip to content
Snippets Groups Projects
Unverified Commit 14948393 authored by Jonas Theis's avatar Jonas Theis Committed by GitHub
Browse files

Integration tests (#312)

* Add docker compose for running integration tests.
Runs entry_node and arbitrary number of peers in docker network

* Fix permission denied in container if run without mounting a `rw` volume making it possible to run as throw-away container.
Remove `VOLUME` from Dockerfile as this only pollutes host system with anonymous volumes.

* Use named network for easier external use

* Add test container that discovers peers and waits for autopeering to happen

* Fix min waitForNeighbors

* Add go.sum

* Run integration tests with Github Actions

* Added framework that abstracts the docker network and provides convenience functionality

* Update directory in Github Actions

* Add bash script for automated local test execution

* Add getMessageByHash endpoint

* Adjust to merge changes

* Add methods to easily do HTTP POST requests

* Added relay message test

* Increase client timeout

* Verbose output for tests makes it easier to follow the execution

* Introduce small API wrapper for GoShimmer HTTP API

* Adjust relay test to use new API wrapper

* WIP: Docker logs

* Fix issue with serving visualizer analysis server of entry node

* Persist logs of containers after CI run

* Fix test file

* Fix uploading of artifacts

* Save all containers' logs as artifacts

* Create logs files also with local run

* Add possibility to retrieve logs from a peer via Docker logs

* Make tester part of the goshimmer module to make code sharing possible

* Use client/lib to make HTTP requests in tester

* Fix unit test directory

* Add comments/doc to the code

* Add readme

* Move tester to own module and don't build container but use existing golang one instead

* Address PR comments

* Adjust to merge

* Only use 1 config file for all containers

* go mod tidy

* Rename client lib base url
parent 7eaae004
No related branches found
No related tags found
No related merge requests found
module github.com/iotaledger/goshimmer/tools/integration-tests/tester
go 1.14
require (
github.com/Microsoft/go-winio v0.4.14 // indirect
github.com/docker/distribution v2.7.1+incompatible // indirect
github.com/docker/docker v1.13.1
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/iotaledger/goshimmer v0.1.3
github.com/opencontainers/go-digest v1.0.0-rc1 // indirect
github.com/stretchr/testify v1.5.1
)
replace github.com/iotaledger/goshimmer => ../../..
This diff is collapsed.
package tests
import (
"bufio"
"regexp"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// TestDockerLogs simply verifies that a peer's log message contains "GoShimmer".
// Using the combination of logs and regular expressions can be useful to test a certain peer's behavior.
func TestDockerLogs(t *testing.T) {
r := regexp.MustCompile("GoShimmer")
for _, p := range f.Peers() {
log, err := p.Logs()
require.NoError(t, err)
assert.True(t, r.MatchReader(bufio.NewReader(log)))
}
}
// Package tests provides the possibility to write integration tests in regular Go style.
// The integration test framework is initialized before any test in the package runs and
// thus can readily be used to make requests to peers and read their logs.
//
// Each tested feature should reside in its own test file and define tests cases as necessary.
package tests
import (
"os"
"testing"
"github.com/iotaledger/goshimmer/tools/integration-tests/tester/framework"
)
var f *framework.Framework
// TestMain gets called by the test utility and is executed before any other test in this package.
// It is therefore used to initialize the integration testing framework.
func TestMain(m *testing.M) {
f = framework.New()
// call the tests
os.Exit(m.Run())
}
package tests
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// TestRelayMessages checks whether messages are actually relayed/gossiped through the network
// by checking the messages' existence on all nodes after a cool down.
func TestRelayMessages(t *testing.T) {
numMessages := 100
ids := make([]string, numMessages)
data := []byte("Test")
// create messages on random peers
for i := 0; i < numMessages; i++ {
id, err := f.RandomPeer().Data(data)
require.NoError(t, err)
ids[i] = id
}
// wait for messages to be gossiped
time.Sleep(5 * time.Second)
// check for messages on every peer
for _, peer := range f.Peers() {
resp, err := peer.FindMessageById(ids)
require.NoError(t, err)
// check for the count of messages
assert.Equal(t, numMessages, len(resp.Messages))
// check that all messages are present in response
outer:
for _, id := range ids {
for _, msg := range resp.Messages {
// if message found skip to next
if msg.Id == id {
continue outer
}
}
t.Errorf("MessageId=%s not found in peer %s.", id, peer.String())
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment