mirror of
https://github.com/logos-storage/logos-storage-network-testing.git
synced 2026-05-22 17:59:27 +00:00
UPD refactor tests
This commit is contained in:
parent
36502ff2cf
commit
c2efa3013e
@ -1,7 +1,6 @@
|
|||||||
package codex
|
package codex
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
@ -10,6 +9,7 @@ import (
|
|||||||
"github.com/guseggert/clustertest/cluster"
|
"github.com/guseggert/clustertest/cluster"
|
||||||
"github.com/guseggert/clustertest/cluster/basic"
|
"github.com/guseggert/clustertest/cluster/basic"
|
||||||
"github.com/guseggert/clustertest/cluster/docker"
|
"github.com/guseggert/clustertest/cluster/docker"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -29,59 +29,36 @@ func TestHello(t *testing.T) {
|
|||||||
addrs := "127.0.0.1"
|
addrs := "127.0.0.1"
|
||||||
for i, node := range nodes {
|
for i, node := range nodes {
|
||||||
node := node.Context(groupCtx)
|
node := node.Context(groupCtx)
|
||||||
if i == 0 {
|
if i <= 1 {
|
||||||
group.Go(func() error {
|
group.Go(func() error {
|
||||||
// host node
|
// host node
|
||||||
stdout := &bytes.Buffer{}
|
ip, err := getIp(groupCtx, node)
|
||||||
stderr := &bytes.Buffer{}
|
if err != nil {
|
||||||
// when running api on 8080, the host node will not be able to run due to nodeagent
|
t.Errorf("failed to get ip: %s", err)
|
||||||
|
t.Errorf("HOST EOutput: %s\n", ip)
|
||||||
// gets node ip
|
}
|
||||||
_, err := node.Run(cluster.StartProcRequest{
|
fmt.Println("ip: ", ip)
|
||||||
Command: "hostname",
|
output, err := createCodexInstance(groupCtx, node)
|
||||||
Args: []string{"-I"},
|
|
||||||
Stdout: stdout,
|
|
||||||
})
|
|
||||||
fmt.Println(stdout.String())
|
|
||||||
|
|
||||||
_, err = node.StartProc(cluster.StartProcRequest{
|
|
||||||
Command: "./build/codex",
|
|
||||||
Args: []string{"--metrics", "--api-port=8090", "--data-dir=`pwd`/Codex1", "--disc-port=8070", "--log-level=TRACE"},
|
|
||||||
Stdout: stdout,
|
|
||||||
Stderr: stderr,
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf(`starting host on node %d: %s`, i, err)
|
t.Errorf(`starting host on node %d: %s`, i, err)
|
||||||
t.Errorf("HOST EOutput: %s\n", stderr.String())
|
t.Errorf("HOST EOutput: %s\n", output)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Println("---------------------")
|
|
||||||
fmt.Printf("HOST Output: %s\n", stdout.String())
|
|
||||||
|
|
||||||
// codex seems to exit upon function exit
|
|
||||||
runout := &bytes.Buffer{}
|
|
||||||
runerr := &bytes.Buffer{}
|
|
||||||
// code below runs a local call to the api, WORKS only with localhost and not ip
|
// code below runs a local call to the api, WORKS only with localhost and not ip
|
||||||
time.Sleep(2 * time.Second)
|
time.Sleep(2 * time.Second)
|
||||||
for i := 0; i < 5; i++ {
|
t.Log(output)
|
||||||
|
for x := 0; x < 2; x++ {
|
||||||
group.Go(func() error {
|
group.Go(func() error {
|
||||||
proc, err := node.StartProc(cluster.StartProcRequest{
|
output, code, err := debugInfoCall(groupCtx, node, addrs)
|
||||||
Command: "curl",
|
|
||||||
Args: []string{"http://" + addrs + ":8090/api/codex/v1/debug/info"},
|
|
||||||
Stdout: runout,
|
|
||||||
Stderr: runerr,
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("HOST EOutput: %s\n", err)
|
t.Errorf("failed to get debug info: %s", err)
|
||||||
|
t.Errorf("HOST EOutput: %s\n", output)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// fmt.Println("---------------------")
|
fmt.Println("---------------------")
|
||||||
code, err := proc.Wait()
|
t.Log(output)
|
||||||
if err != nil {
|
assert.Equal(t, 0, code, "should be 200")
|
||||||
t.Errorf("HOST EOutput: %s\n", err)
|
t.Logf("HOST %d Exit code: %d\n", i, code)
|
||||||
return err
|
|
||||||
}
|
|
||||||
fmt.Printf("HOST Exit code: %d\n", code.ExitCode)
|
|
||||||
// fmt.Println(runout)
|
// fmt.Println(runout)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
@ -95,16 +72,6 @@ func TestHello(t *testing.T) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// group.Go(func() error {
|
|
||||||
// // calls to the api local and with ip address, DOES NOT WORK
|
|
||||||
// resp, err := http.Get("http://" + addrs + ":8090/api/codex/v1/debug/info")
|
|
||||||
// if err != nil {
|
|
||||||
// log.Fatal(err)
|
|
||||||
// }
|
|
||||||
// fmt.Println(resp)
|
|
||||||
// defer resp.Body.Close()
|
|
||||||
// return nil
|
|
||||||
// })
|
|
||||||
group.Wait()
|
group.Wait()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
59
tests/functional.go
Normal file
59
tests/functional.go
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
package codex
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/guseggert/clustertest/cluster"
|
||||||
|
"github.com/guseggert/clustertest/cluster/basic"
|
||||||
|
)
|
||||||
|
|
||||||
|
func getIp(ctx context.Context, node *basic.Node) (string, error) {
|
||||||
|
stdout := &bytes.Buffer{}
|
||||||
|
stderr := &bytes.Buffer{}
|
||||||
|
proc, err := node.StartProc(cluster.StartProcRequest{
|
||||||
|
Command: "hostname",
|
||||||
|
Args: []string{"-I"},
|
||||||
|
Stdout: stdout,
|
||||||
|
Stderr: stderr,
|
||||||
|
})
|
||||||
|
proc.Wait()
|
||||||
|
if err != nil {
|
||||||
|
return stderr.String(), err
|
||||||
|
}
|
||||||
|
return stdout.String(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func createCodexInstance(ctx context.Context, node *basic.Node) (string, error) {
|
||||||
|
stdout := &bytes.Buffer{}
|
||||||
|
stderr := &bytes.Buffer{}
|
||||||
|
_, err := node.StartProc(cluster.StartProcRequest{
|
||||||
|
Command: "./build/codex",
|
||||||
|
Args: []string{"--metrics", "--api-port=8090", "--data-dir=`pwd`/Codex1", "--disc-port=8070", "--log-level=TRACE"},
|
||||||
|
Stdout: stdout,
|
||||||
|
Stderr: stderr,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return stderr.String(), err
|
||||||
|
}
|
||||||
|
return stdout.String(), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func debugInfoCall(ctx context.Context, node *basic.Node, addrs string) (string, int, error) {
|
||||||
|
stdout := &bytes.Buffer{}
|
||||||
|
stderr := &bytes.Buffer{}
|
||||||
|
proc, err := node.StartProc(cluster.StartProcRequest{
|
||||||
|
Command: "curl",
|
||||||
|
Args: []string{"http://" + addrs + ":8090/api/codex/v1/debug/info"},
|
||||||
|
Stdout: stdout,
|
||||||
|
Stderr: stderr,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return stderr.String(), 1, err
|
||||||
|
}
|
||||||
|
code, _ := proc.Wait()
|
||||||
|
if err != nil {
|
||||||
|
return stderr.String(), code.ExitCode, err
|
||||||
|
}
|
||||||
|
return stdout.String(), code.ExitCode, nil
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user