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

Consider exit status of containers in integration tests (#387)

* Add status code check to network shutdown so that a test fails if a container stops caused by an error

* Speed up Docker network through little caching trick
parent db5b9068
No related branches found
No related tags found
No related merge requests found
...@@ -160,6 +160,16 @@ func (d *DockerContainer) Stop() error { ...@@ -160,6 +160,16 @@ func (d *DockerContainer) Stop() error {
return d.client.ContainerStop(context.Background(), d.id, &duration) return d.client.ContainerStop(context.Background(), d.id, &duration)
} }
// ExitStatus returns the exit status according to the container information.
func (d *DockerContainer) ExitStatus() (int, error) {
resp, err := d.client.ContainerInspect(context.Background(), d.id)
if err != nil {
return -1, err
}
return resp.State.ExitCode, nil
}
// Logs returns the logs of the container as io.ReadCloser. // Logs returns the logs of the container as io.ReadCloser.
func (d *DockerContainer) Logs() (io.ReadCloser, error) { func (d *DockerContainer) Logs() (io.ReadCloser, error) {
options := types.ContainerLogsOptions{ options := types.ContainerLogsOptions{
......
...@@ -155,6 +155,19 @@ func (n *Network) Shutdown() error { ...@@ -155,6 +155,19 @@ func (n *Network) Shutdown() error {
} }
} }
// save exit status of containers to check at end of shutdown process
exitStatus := make(map[string]int, len(n.peers)+1)
exitStatus[containerNameEntryNode], err = n.entryNode.ExitStatus()
if err != nil {
return err
}
for _, p := range n.peers {
exitStatus[p.name], err = p.ExitStatus()
if err != nil {
return err
}
}
// remove containers // remove containers
err = n.entryNode.Remove() err = n.entryNode.Remove()
if err != nil { if err != nil {
...@@ -179,6 +192,13 @@ func (n *Network) Shutdown() error { ...@@ -179,6 +192,13 @@ func (n *Network) Shutdown() error {
return err return err
} }
// check exit codes of containers
for name, status := range exitStatus {
if status != exitStatusSuccessful {
return fmt.Errorf("container %s exited with code %d", name, status)
}
}
return nil return nil
} }
......
...@@ -18,6 +18,8 @@ const ( ...@@ -18,6 +18,8 @@ const (
dockerLogsPrefixLen = 8 dockerLogsPrefixLen = 8
dkgMaxTries = 50 dkgMaxTries = 50
exitStatusSuccessful = 0
) )
// GoShimmerConfig defines the config of a GoShimmer node. // GoShimmerConfig defines the config of a GoShimmer node.
......
...@@ -19,7 +19,7 @@ func TestSynchronization(t *testing.T) { ...@@ -19,7 +19,7 @@ func TestSynchronization(t *testing.T) {
initalPeers := 4 initalPeers := 4
n, err := f.CreateNetwork("common_TestSynchronization", initalPeers, 2, config) n, err := f.CreateNetwork("common_TestSynchronization", initalPeers, 2, config)
require.NoError(t, err) require.NoError(t, err)
defer n.Shutdown() defer ShutdownNetwork(t, n)
// wait for peers to change their state to synchronized // wait for peers to change their state to synchronized
time.Sleep(5 * time.Second) time.Sleep(5 * time.Second)
......
...@@ -23,7 +23,7 @@ func TestDRNG(t *testing.T) { ...@@ -23,7 +23,7 @@ func TestDRNG(t *testing.T) {
drng, err := f.CreateDRNGNetwork("TestDRNG", 5, 8, 3) drng, err := f.CreateDRNGNetwork("TestDRNG", 5, 8, 3)
require.NoError(t, err) require.NoError(t, err)
defer drng.Shutdown() defer ShutdownNetwork(t, drng)
// wait for randomness generation to be started // wait for randomness generation to be started
log.Printf("Waiting for randomness generation to be started...\n") log.Printf("Waiting for randomness generation to be started...\n")
......
...@@ -11,7 +11,7 @@ import ( ...@@ -11,7 +11,7 @@ import (
func TestPersistence(t *testing.T) { func TestPersistence(t *testing.T) {
n, err := f.CreateNetwork("message_TestPersistence", 4, 2) n, err := f.CreateNetwork("message_TestPersistence", 4, 2)
require.NoError(t, err) require.NoError(t, err)
defer n.Shutdown() defer ShutdownNetwork(t, n)
// wait for peers to change their state to synchronized // wait for peers to change their state to synchronized
time.Sleep(5 * time.Second) time.Sleep(5 * time.Second)
......
...@@ -19,6 +19,10 @@ type DataMessageSent struct { ...@@ -19,6 +19,10 @@ type DataMessageSent struct {
issuerPublicKey string issuerPublicKey string
} }
type Shutdowner interface {
Shutdown() error
}
// sendDataMessagesOnRandomPeer sends data messages on a random peer and saves the sent message to a map. // sendDataMessagesOnRandomPeer sends data messages on a random peer and saves the sent message to a map.
func sendDataMessagesOnRandomPeer(t *testing.T, peers []*framework.Peer, numMessages int, idsMap ...map[string]DataMessageSent) map[string]DataMessageSent { func sendDataMessagesOnRandomPeer(t *testing.T, peers []*framework.Peer, numMessages int, idsMap ...map[string]DataMessageSent) map[string]DataMessageSent {
var ids map[string]DataMessageSent var ids map[string]DataMessageSent
...@@ -90,3 +94,9 @@ func checkForMessageIds(t *testing.T, peers []*framework.Peer, ids map[string]Da ...@@ -90,3 +94,9 @@ func checkForMessageIds(t *testing.T, peers []*framework.Peer, ids map[string]Da
} }
} }
} }
// ShutdownNetwork shuts down the network and reports errors.
func ShutdownNetwork(t *testing.T, n Shutdowner) {
err := n.Shutdown()
require.NoError(t, err)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment