Updated clustertest code
This commit is contained in:
parent
1981590320
commit
86e91cd2df
|
@ -1,3 +1,6 @@
|
|||
[submodule "nim-codex"]
|
||||
path = nim-codex
|
||||
url = git@github.com:status-im/nim-codex.git
|
||||
[submodule "clustertest"]
|
||||
path = clustertest
|
||||
url = git@github.com:guseggert/clustertest.git
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Subproject commit a6539fc7cb6577db5ad007626f14423e8ae4d6b3
|
|
@ -0,0 +1,34 @@
|
|||
module network-testing-codex.com/m
|
||||
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/guseggert/clustertest v0.0.0-20230202214239-a6539fc7cb65
|
||||
golang.org/x/sync v0.1.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
|
||||
github.com/Microsoft/go-winio v0.6.0 // indirect
|
||||
github.com/docker/distribution v2.8.1+incompatible // indirect
|
||||
github.com/docker/docker v20.10.22+incompatible // indirect
|
||||
github.com/docker/go-connections v0.4.0 // indirect
|
||||
github.com/docker/go-units v0.5.0 // indirect
|
||||
github.com/gogo/protobuf v1.3.2 // indirect
|
||||
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
|
||||
github.com/hashicorp/go-retryablehttp v0.7.2 // indirect
|
||||
github.com/julienschmidt/httprouter v1.3.0 // indirect
|
||||
github.com/klauspost/compress v1.13.5 // indirect
|
||||
github.com/opencontainers/go-digest v1.0.0 // indirect
|
||||
github.com/opencontainers/image-spec v1.0.3-0.20220114050600-8b9d41f48198 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/sirupsen/logrus v1.9.0 // indirect
|
||||
go.uber.org/atomic v1.7.0 // indirect
|
||||
go.uber.org/multierr v1.6.0 // indirect
|
||||
go.uber.org/zap v1.24.0 // indirect
|
||||
golang.org/x/mod v0.7.0 // indirect
|
||||
golang.org/x/net v0.2.0 // indirect
|
||||
golang.org/x/sys v0.3.0 // indirect
|
||||
golang.org/x/tools v0.3.0 // indirect
|
||||
nhooyr.io/websocket v1.8.7 // indirect
|
||||
)
|
|
@ -0,0 +1,99 @@
|
|||
package codex
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/guseggert/clustertest/cluster"
|
||||
"github.com/guseggert/clustertest/cluster/basic"
|
||||
"github.com/guseggert/clustertest/cluster/docker"
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
func TestHello(t *testing.T) {
|
||||
run := func(t *testing.T, name string, impl cluster.Cluster) {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Create the cluster.
|
||||
c := basic.New(impl)
|
||||
t.Cleanup(c.MustCleanup)
|
||||
|
||||
t.Logf("Launching %s nodes", name)
|
||||
nodes := c.MustNewNodes(5)
|
||||
|
||||
group, groupCtx := errgroup.WithContext(context.Background())
|
||||
addrs := "/ip4/0.0.0.0/tcp/50880"
|
||||
for i, node := range nodes {
|
||||
node := node.Context(groupCtx)
|
||||
if i == 0 {
|
||||
// host node
|
||||
stdout := &bytes.Buffer{}
|
||||
stderr := &bytes.Buffer{}
|
||||
_, err := node.StartProc(cluster.StartProcRequest{
|
||||
Command: "./build/codex",
|
||||
Args: []string{"--nat=100.80.179.146", "--metrics", "--api-port=8080", "--data-dir=`pwd`/Codex1", "--disc-port=8090", "--log-level=TRACE", "-i=" + addrs, "-q=1099511627776"},
|
||||
Stdout: stdout,
|
||||
Stderr: stderr,
|
||||
})
|
||||
if err != nil {
|
||||
t.Errorf(`starting client on node %d: %s`, i, err)
|
||||
continue
|
||||
}
|
||||
// extract spr from host node output
|
||||
time.Sleep(2 * time.Second)
|
||||
if err != nil {
|
||||
t.Errorf(`waiting for client on node %d: %s`, i, err)
|
||||
continue
|
||||
}
|
||||
t.Logf("HOST Output: %s\n\n", stdout.String())
|
||||
t.Logf("HOST EOutput: %s\n\n", stderr.String())
|
||||
// t.Log("HOST proc: ", code)
|
||||
|
||||
continue
|
||||
} else {
|
||||
group.Go(func() error {
|
||||
// wait for host to start
|
||||
resp, err := http.Get("http://127.0.0.1:8080/api/codex/v1/info")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Println(resp)
|
||||
defer resp.Body.Close()
|
||||
return nil
|
||||
})
|
||||
} // else {
|
||||
// group.Go(func() error {
|
||||
// stdout := &bytes.Buffer{}
|
||||
// stderr := &bytes.Buffer{}
|
||||
// _, err := node.StartProc(cluster.StartProcRequest{
|
||||
// Command: "./build/codex",
|
||||
// Args: []string{"--data-dir=\"$(pwd)/Codex2\"", "--api-port=8081", "--disc-port=8091", "--bootstrap-node=$(curl http://127.0.0.1:8080/api/codex/v1/debug/info 2>/dev/null | jq -r .spr)", "--log-level=TRACE", "-i=/ip4/0.0.0.0/tcp/50881", "-q=1099511627776"},
|
||||
// Stdout: stdout,
|
||||
// Stderr: stderr,
|
||||
// })
|
||||
// if err != nil {
|
||||
// t.Errorf(`starting client on node %d: %s`, i, err)
|
||||
// return nil
|
||||
// }
|
||||
// t.Logf("CLIENT Output: %s\n\n", stdout.String())
|
||||
// t.Logf("CLIENT EOutput: %s\n\n", stderr.String())
|
||||
// // t.Log("CLIENT proc: ", code)
|
||||
|
||||
// return nil
|
||||
// })
|
||||
// }
|
||||
}
|
||||
group.Wait()
|
||||
// TODO ping host using get request
|
||||
})
|
||||
}
|
||||
|
||||
// run(t, "local cluster", local.MustNewCluster())
|
||||
run(t, "Docker cluster", docker.MustNewCluster().WithBaseImage("corbo12/nim-codex:v3"))
|
||||
}
|
Binary file not shown.
Loading…
Reference in New Issue