84 lines
2.2 KiB
Go
Raw Permalink Normal View History

2023-02-16 16:53:56 +01:00
// This test is a simple test to check if the cluster is running and can be used
2023-02-03 12:47:10 +01:00
package codex
import (
"context"
"fmt"
"testing"
"time"
"github.com/guseggert/clustertest/cluster"
"github.com/guseggert/clustertest/cluster/basic"
"github.com/guseggert/clustertest/cluster/docker"
2023-02-16 15:54:28 +01:00
"github.com/stretchr/testify/assert"
2023-02-03 12:47:10 +01:00
"golang.org/x/sync/errgroup"
)
2023-02-16 16:53:56 +01:00
func TestInfo1(t *testing.T) {
2023-02-03 12:47:10 +01:00
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)
2023-02-09 15:36:41 +01:00
nodes := c.MustNewNodes(2)
2023-02-03 12:47:10 +01:00
group, groupCtx := errgroup.WithContext(context.Background())
2023-02-10 11:32:33 +01:00
addrs := "127.0.0.1"
2023-02-03 12:47:10 +01:00
for i, node := range nodes {
node := node.Context(groupCtx)
2023-02-16 15:54:28 +01:00
if i <= 1 {
2023-02-08 14:19:47 +01:00
group.Go(func() error {
// host node
2023-02-16 15:54:28 +01:00
ip, err := getIp(groupCtx, node)
if err != nil {
t.Errorf("failed to get ip: %s", err)
t.Errorf("HOST EOutput: %s\n", ip)
}
fmt.Println("ip: ", ip)
output, err := createCodexInstance(groupCtx, node)
2023-02-08 14:19:47 +01:00
if err != nil {
2023-02-10 11:32:33 +01:00
t.Errorf(`starting host on node %d: %s`, i, err)
2023-02-16 15:54:28 +01:00
t.Errorf("HOST EOutput: %s\n", output)
2023-02-08 14:19:47 +01:00
return err
}
2023-02-10 11:32:33 +01:00
// code below runs a local call to the api, WORKS only with localhost and not ip
time.Sleep(2 * time.Second)
2023-02-16 15:54:28 +01:00
t.Log(output)
for x := 0; x < 2; x++ {
2023-02-10 15:05:29 +01:00
group.Go(func() error {
2023-02-16 15:54:28 +01:00
output, code, err := debugInfoCall(groupCtx, node, addrs)
2023-02-10 15:05:29 +01:00
if err != nil {
2023-02-16 15:54:28 +01:00
t.Errorf("failed to get debug info: %s", err)
t.Errorf("HOST EOutput: %s\n", output)
2023-02-10 15:05:29 +01:00
return err
}
2023-02-16 15:54:28 +01:00
fmt.Println("---------------------")
t.Log(output)
2023-02-16 16:53:56 +01:00
assert.Equal(t, 0, code, "should be 0")
2023-02-16 15:54:28 +01:00
t.Logf("HOST %d Exit code: %d\n", i, code)
2023-02-10 15:05:29 +01:00
// fmt.Println(runout)
return nil
})
2023-02-10 11:32:33 +01:00
}
2023-02-09 15:36:41 +01:00
// t.Logf("HOST Output: %s\n\n", stdout.String())
// t.Logf("HOST EOutput: %s\n\n", stderr.String())
2023-02-08 14:19:47 +01:00
return nil
2023-02-03 12:47:10 +01:00
})
2023-02-10 11:32:33 +01:00
time.Sleep(5 * time.Second)
2023-02-03 12:47:10 +01:00
continue
2023-02-10 15:05:29 +01:00
}
2023-02-03 12:47:10 +01:00
}
group.Wait()
})
2023-02-10 11:32:33 +01:00
2023-02-03 12:47:10 +01:00
}
// run(t, "local cluster", local.MustNewCluster())
2023-02-09 15:36:41 +01:00
run(t, "Docker cluster", docker.MustNewCluster().WithBaseImage("corbo12/nim-codex:v4"))
2023-02-03 12:47:10 +01:00
}