From 9d6d994ada400fd786b2f1eb409eea432dbf334c Mon Sep 17 00:00:00 2001 From: Augustus <14297860+augustbleeds@users.noreply.github.com> Date: Thu, 15 Feb 2024 14:13:28 -0500 Subject: [PATCH] working local soaktests (#357) --- integration-tests/common/common.go | 80 +++++++++++++++++++++++++++--- scripts/core.down.sh | 2 +- scripts/core.sh | 2 +- 3 files changed, 76 insertions(+), 8 deletions(-) diff --git a/integration-tests/common/common.go b/integration-tests/common/common.go index d51e578f8..29a79054f 100644 --- a/integration-tests/common/common.go +++ b/integration-tests/common/common.go @@ -1,7 +1,9 @@ package common import ( + "bytes" "fmt" + "io" "os" "os/exec" "regexp" @@ -157,12 +159,79 @@ HTTPSPort = 0 c.ChainlinkConfig = chainlinkConfig log.Debug().Str("toml", chainlinkConfig).Msg("Created chainlink config") - envConfig := &environment.Config{NamespacePrefix: "chainlink-ocr-starknet", TTL: c.TTL, Test: t} - - c.Env = environment.New(envConfig) + c.Env = &environment.Environment{} return c } +// CapturingPassThroughWriter is a writer that remembers +// data written to it and passes it to w +type CapturingPassThroughWriter struct { + buf bytes.Buffer + w io.Writer +} + +// NewCapturingPassThroughWriter creates new CapturingPassThroughWriter +func NewCapturingPassThroughWriter(w io.Writer) *CapturingPassThroughWriter { + return &CapturingPassThroughWriter{ + w: w, + } +} + +func (w *CapturingPassThroughWriter) Write(d []byte) (int, error) { + w.buf.Write(d) + return w.w.Write(d) +} + +// Bytes returns bytes written to the writer +func (w *CapturingPassThroughWriter) Bytes() []byte { + return w.buf.Bytes() +} + +func debug(cmd *exec.Cmd) error { + stdout, err := cmd.StdoutPipe() + if err != nil { + panic(err) + } + stderr, err := cmd.StderrPipe() + if err != nil { + panic(err) + } + + if err := cmd.Start(); err != nil { + panic(err) + } + + doneStdOut := make(chan any) + doneStdErr := make(chan any) + osstdout := NewCapturingPassThroughWriter(os.Stdout) + osstderr := NewCapturingPassThroughWriter(os.Stderr) + go handleOutput(osstdout, stdout, doneStdOut) + go handleOutput(osstderr, stderr, doneStdErr) + + err = cmd.Wait() + + errStdOut := <-doneStdOut + if errStdOut != nil { + fmt.Println("error writing to standard out") + } + + errStdErr := <-doneStdErr + if errStdErr != nil { + fmt.Println("error writing to standard in") + } + + if err != nil { + fmt.Printf("Command finished with error: %v\n", err) + } + + return err +} + +func handleOutput(dst io.Writer, src io.Reader, done chan<- any) { + _, err := io.Copy(dst, src) + done <- err +} + func (c *Common) SetLocalEnvironment(t *testing.T) { // Run scripts to set up local test environment log.Info().Msg("Starting starknet-devnet container...") @@ -178,9 +247,8 @@ func (c *Common) SetLocalEnvironment(t *testing.T) { log.Info().Msg("Starting core nodes...") cmd := exec.Command("../../scripts/core.sh") cmd.Env = append(os.Environ(), fmt.Sprintf("CL_CONFIG=%s", c.ChainlinkConfig)) - // out, err := cmd.Output() - // fmt.Println(string(out)) - err = cmd.Run() + // easy debug + err = debug(cmd) require.NoError(t, err, "Could not start core nodes") log.Info().Msg("Set up local stack complete.") diff --git a/scripts/core.down.sh b/scripts/core.down.sh index 3bd430b27..c211a835f 100755 --- a/scripts/core.down.sh +++ b/scripts/core.down.sh @@ -4,7 +4,7 @@ echo "Cleaning up core containers.." echo "Checking for existing 'chainlink.core' docker containers..." -for i in {1..4} +for i in {1..5} do echo " Checking for chainlink.core.$i" dpid=$(docker ps -a | grep chainlink.core.$i | awk '{print $1}') diff --git a/scripts/core.sh b/scripts/core.sh index 2799f2808..85db2d947 100755 --- a/scripts/core.sh +++ b/scripts/core.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -set -euo pipefail +set -euox pipefail bash "$(dirname -- "$0")/core.down.sh"