Skip to content

Commit

Permalink
working local soaktests (#357)
Browse files Browse the repository at this point in the history
  • Loading branch information
augustbleeds authored Feb 15, 2024
1 parent c20ef0f commit 9d6d994
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 8 deletions.
80 changes: 74 additions & 6 deletions integration-tests/common/common.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package common

import (
"bytes"
"fmt"
"io"
"os"
"os/exec"
"regexp"
Expand Down Expand Up @@ -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...")
Expand All @@ -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.")

Expand Down
2 changes: 1 addition & 1 deletion scripts/core.down.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}')
Expand Down
2 changes: 1 addition & 1 deletion scripts/core.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

set -euo pipefail
set -euox pipefail

bash "$(dirname -- "$0")/core.down.sh"

Expand Down

0 comments on commit 9d6d994

Please sign in to comment.