From 1129915446d3539a980a65d6998a068e8ba0ef45 Mon Sep 17 00:00:00 2001 From: "Andrew Jackson (Ajax)" Date: Mon, 22 Jul 2024 16:35:25 -0500 Subject: [PATCH 1/6] test task --- cmd/curio/test-cli.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/curio/test-cli.go b/cmd/curio/test-cli.go index 84e8ad1c5..4d7299c2a 100644 --- a/cmd/curio/test-cli.go +++ b/cmd/curio/test-cli.go @@ -119,7 +119,7 @@ var wdPostTaskCmd = &cli.Command{ for len(taskIDs) > 0 { time.Sleep(time.Second) - err = deps.DB.QueryRow(ctx, `SELECT task_id, result FROM harmony_test WHERE task_id IN $1`, taskIDs).Scan(&taskID, &result) + err = deps.DB.QueryRow(ctx, `SELECT task_id, result FROM harmony_test WHERE task_id IN ($1)`, taskIDs).Scan(&taskID, &result) if err != nil { return xerrors.Errorf("reading result from harmony_test: %w", err) } @@ -141,7 +141,7 @@ var wdPostTaskCmd = &cli.Command{ result sql.NullString errmsg sql.NullString } - err = deps.DB.Select(ctx, &hist, `SELECT id, task_id, result, err FROM harmony_task_history WHERE task_id IN $1 ORDER BY work_end DESC`, taskIDs) + err = deps.DB.Select(ctx, &hist, `SELECT id, task_id, result, err FROM harmony_task_history WHERE task_id IN ($1) ORDER BY work_end DESC`, taskIDs) if err != nil && err != pgx.ErrNoRows { return xerrors.Errorf("reading result from harmony_task_history: %w", err) } @@ -161,7 +161,7 @@ var wdPostTaskCmd = &cli.Command{ { // look for fails var found []int64 - err = deps.DB.Select(ctx, found, `SELECT task_id FROM harmony_task WHERE id IN $1`, taskIDs) + err = deps.DB.Select(ctx, found, `SELECT task_id FROM harmony_task WHERE id IN ($1)`, taskIDs) if err != nil && err != pgx.ErrNoRows { return xerrors.Errorf("reading result from harmony_task: %w", err) } From 832a376c5094d1bcd656fe9d7a17cf97032fdae2 Mon Sep 17 00:00:00 2001 From: "Andrew Jackson (Ajax)" Date: Mon, 22 Jul 2024 18:55:36 -0500 Subject: [PATCH 2/6] test cli --- .circleci/config.yml | 76 ++++++++++++++++++++++++++++++ cmd/curio/test-cli.go | 2 + harmony/harmonydb/harmonydb.go | 3 +- itests/curio_test.go | 16 ++++--- itests_with_chain/cli_post_test.go | 46 ++++++++++++++++++ 5 files changed, 135 insertions(+), 8 deletions(-) create mode 100644 itests_with_chain/cli_post_test.go diff --git a/.circleci/config.yml b/.circleci/config.yml index c2c2e6335..c4c042fb9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -192,6 +192,74 @@ jobs: path: /tmp/test-reports - store_artifacts: path: /tmp/test-artifacts/<< parameters.suite >>.json + test_with_chain: + description: | + Run tests with gotestsum. + working_directory: ~/curio + parameters: &test-params + resource_class: + type: string + default: medium+ + go-test-flags: + type: string + default: "-timeout 20m" + description: Flags passed to go test. + target: + type: string + default: "./..." + description: Import paths of packages to be tested. + proofs-log-test: + type: string + default: "0" + get-params: + type: boolean + default: false + suite: + type: string + default: unit + description: Test suite name to report to CircleCI. + docker: + - image: cimg/go:1.22 + environment: + CURIO_HARMONYDB_HOSTS: yugabyte + LOTUS_HARMONYDB_HOSTS: yugabyte + - image: yugabytedb/yugabyte:2.21.0.1-b1 + command: bin/yugabyted start --daemon=false + name: yugabyte + - image: ghcr.io/chainsafe/forest:latest + command: forest /bin/bash + name: forest + resource_class: << parameters.resource_class >> + steps: + - install-ubuntu-deps + - attach_workspace: + at: ~/ + - when: + condition: << parameters.get-params >> + steps: + - download-params + - run: + name: go test + environment: + TEST_RUSTPROOFS_LOGS: << parameters.proofs-log-test >> + SKIP_CONFORMANCE: "1" + CURIO_SRC_DIR: /home/circleci/project + command: | + mkdir -p /tmp/test-reports/<< parameters.suite >> + mkdir -p /tmp/test-artifacts + dockerize -wait tcp://yugabyte:5433 -timeout 3m + env + gotestsum \ + --format standard-verbose \ + --junitfile /tmp/test-reports/<< parameters.suite >>/junit.xml \ + --jsonfile /tmp/test-artifacts/<< parameters.suite >>.json \ + --packages="<< parameters.target >>" \ + -- << parameters.go-test-flags >> + no_output_timeout: 30m + - store_test_results: + path: /tmp/test-reports + - store_artifacts: + path: /tmp/test-artifacts/<< parameters.suite >>.json lint-all: description: | @@ -271,3 +339,11 @@ workflows: target: "./itests/curio_test.go" get-params: true resource_class: 2xlarge + - test_with_chain: + name: test-itest-chain + requires: + - build + suite: itest-chain + target: "./itests_with_chain/cli_post_test.go" + get-params: true + resource_class: 2xlarge diff --git a/cmd/curio/test-cli.go b/cmd/curio/test-cli.go index 4d7299c2a..f54f95ce3 100644 --- a/cmd/curio/test-cli.go +++ b/cmd/curio/test-cli.go @@ -169,6 +169,7 @@ var wdPostTaskCmd = &cli.Command{ log.Infof("Tasks found in harmony_task: %v", found) } } + fmt.Println("All tasks completed successfully") return nil }, } @@ -244,6 +245,7 @@ It will not send any messages to the chain. Since it can compute any deadline, o } } + fmt.Println("All tasks completed successfully") return nil }, } diff --git a/harmony/harmonydb/harmonydb.go b/harmony/harmonydb/harmonydb.go index 7dadc4078..9b2d295c8 100644 --- a/harmony/harmonydb/harmonydb.go +++ b/harmony/harmonydb/harmonydb.go @@ -6,6 +6,7 @@ import ( "fmt" "math/rand" "net" + "os" "regexp" "sort" "strconv" @@ -55,7 +56,7 @@ func NewFromConfig(cfg config.HarmonyDB) (*DB, error) { cfg.Password, cfg.Database, cfg.Port, - "", + ITestID(os.Getenv("CURIO_ITEST_DO_NOT_USE")), // ONLY for testing ) } diff --git a/itests/curio_test.go b/itests/curio_test.go index 40ee2ddf5..6922ec9b4 100644 --- a/itests/curio_test.go +++ b/itests/curio_test.go @@ -45,6 +45,14 @@ import ( "github.com/filecoin-project/lotus/storage/sealer/storiface" ) +var dbConfig = config.HarmonyDB{ + Hosts: []string{envElse("CURIO_HARMONYDB_HOSTS", "127.0.0.1")}, + Database: "yugabyte", + Username: "yugabyte", + Password: "yugabyte", + Port: "5433", +} + func TestCurioNewActor(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() @@ -64,13 +72,7 @@ func TestCurioNewActor(t *testing.T) { require.NoError(t, err) sharedITestID := harmonydb.ITestNewID() - dbConfig := config.HarmonyDB{ - Hosts: []string{envElse("CURIO_HARMONYDB_HOSTS", "127.0.0.1")}, - Database: "yugabyte", - Username: "yugabyte", - Password: "yugabyte", - Port: "5433", - } + db, err := harmonydb.NewFromConfigWithITestID(t, dbConfig, sharedITestID) require.NoError(t, err) diff --git a/itests_with_chain/cli_post_test.go b/itests_with_chain/cli_post_test.go new file mode 100644 index 000000000..43ebc57b7 --- /dev/null +++ b/itests_with_chain/cli_post_test.go @@ -0,0 +1,46 @@ +package itests + +import ( + "bytes" + "io" + "os" + "os/exec" + "strconv" + "testing" + + "golang.org/x/exp/rand" +) + +type CliThing struct { + *exec.Cmd + *bytes.Buffer +} + +func CliEnv() func(name string, args ...string) *CliThing { + itest := "CURIO_ITEST_DO_NOT_USE=" + strconv.Itoa(rand.Intn(99999)) + return func(name string, args ...string) *CliThing { + cmd := exec.Command(name, args...) + cmd.Env = append(cmd.Env, itest) + cmd.Env = append(cmd.Env, "PATH="+os.Getenv("PATH")) + b := &bytes.Buffer{} + cmd.Stdout = io.MultiWriter(os.Stdout, b) + cmd.Stderr = io.MultiWriter(os.Stderr, b) + return &CliThing{cmd, b} + } +} +func TestCliPost(t *testing.T) { + thistest := CliEnv() + os.WriteFile("/tmp/base.toml", []byte(""), 0644) + err := thistest("../curio", "config", "set", "/tmp/base.toml").Run() + if err != nil { + t.Fatal(err) + } + cmd := thistest("../curio", "test", "window-post", "here") + err = cmd.Run() + if err != nil { + t.Fatal(err) + } + if !bytes.Contains(cmd.Bytes(), []byte("All tasks complete")) { + t.Fatal("unexpected output") + } +} From c493c7f2674e265cc361ead882af7016250d3886 Mon Sep 17 00:00:00 2001 From: "Andrew Jackson (Ajax)" Date: Mon, 29 Jul 2024 10:49:06 -0500 Subject: [PATCH 3/6] yugabyte as host --- .circleci/config.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index c4c042fb9..ca1321f8e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -176,6 +176,8 @@ jobs: TEST_RUSTPROOFS_LOGS: << parameters.proofs-log-test >> SKIP_CONFORMANCE: "1" CURIO_SRC_DIR: /home/circleci/project + CURIO_HARMONYDB_HOSTS: yugabyte + LOTUS_HARMONYDB_HOSTS: yugabyte command: | mkdir -p /tmp/test-reports/<< parameters.suite >> mkdir -p /tmp/test-artifacts @@ -244,6 +246,8 @@ jobs: TEST_RUSTPROOFS_LOGS: << parameters.proofs-log-test >> SKIP_CONFORMANCE: "1" CURIO_SRC_DIR: /home/circleci/project + CURIO_HARMONYDB_HOSTS: yugabyte + LOTUS_HARMONYDB_HOSTS: yugabyte command: | mkdir -p /tmp/test-reports/<< parameters.suite >> mkdir -p /tmp/test-artifacts From 07f3ffc4bbda2c73aedcd9768b25e7b0ff3f425f Mon Sep 17 00:00:00 2001 From: "Andrew Jackson (Ajax)" Date: Mon, 29 Jul 2024 17:02:32 -0500 Subject: [PATCH 4/6] simpler cpi test with rq --- go.mod | 1 + go.sum | 2 ++ itests_with_chain/cli_post_test.go | 17 +++++------------ 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index 9e085b8f7..4f2231df2 100644 --- a/go.mod +++ b/go.mod @@ -281,6 +281,7 @@ require ( github.com/sirupsen/logrus v1.9.2 // indirect github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect + github.com/test-go/testify v1.1.4 // indirect github.com/triplewz/poseidon v0.0.0-20230828015038-79d8165c88ed // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasttemplate v1.0.1 // indirect diff --git a/go.sum b/go.sum index e5c32a249..216cca057 100644 --- a/go.sum +++ b/go.sum @@ -1259,6 +1259,8 @@ github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpP github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY= github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc= github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA= +github.com/test-go/testify v1.1.4 h1:Tf9lntrKUMHiXQ07qBScBTSA0dhYQlu83hswqelv1iE= +github.com/test-go/testify v1.1.4/go.mod h1:rH7cfJo/47vWGdi4GPj16x3/t1xGOj2YxzmNQzk2ghU= github.com/tidwall/gjson v1.6.0/go.mod h1:P256ACg0Mn+j1RXIDXoss50DeIABTYK1PULOJHhxOls= github.com/tidwall/gjson v1.14.4 h1:uo0p8EbA09J7RQaflQ1aBRffTR7xedD2bcIVSYxLnkM= github.com/tidwall/gjson v1.14.4/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= diff --git a/itests_with_chain/cli_post_test.go b/itests_with_chain/cli_post_test.go index 43ebc57b7..3d45d5180 100644 --- a/itests_with_chain/cli_post_test.go +++ b/itests_with_chain/cli_post_test.go @@ -8,6 +8,7 @@ import ( "strconv" "testing" + "github.com/test-go/testify/require" "golang.org/x/exp/rand" ) @@ -30,17 +31,9 @@ func CliEnv() func(name string, args ...string) *CliThing { } func TestCliPost(t *testing.T) { thistest := CliEnv() - os.WriteFile("/tmp/base.toml", []byte(""), 0644) - err := thistest("../curio", "config", "set", "/tmp/base.toml").Run() - if err != nil { - t.Fatal(err) - } + require.NoError(t, os.WriteFile("/tmp/base.toml", []byte(""), 0644)) + require.NoError(t, thistest("../curio", "config", "set", "/tmp/base.toml").Run()) cmd := thistest("../curio", "test", "window-post", "here") - err = cmd.Run() - if err != nil { - t.Fatal(err) - } - if !bytes.Contains(cmd.Bytes(), []byte("All tasks complete")) { - t.Fatal("unexpected output") - } + require.NoError(t, cmd.Run()) + require.Equal(t, "All tasks complete\n", cmd.Buffer.String()) } From c17cf7c294b01fbadf8f82d2e78c00819a763b37 Mon Sep 17 00:00:00 2001 From: "Andrew Jackson (Ajax)" Date: Mon, 29 Jul 2024 17:04:35 -0500 Subject: [PATCH 5/6] tidy --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index b5461a4db..ba2b35568 100644 --- a/go.mod +++ b/go.mod @@ -61,6 +61,7 @@ require ( github.com/samber/lo v1.39.0 github.com/snadrus/must v0.0.0-20240605044437-98cedd57f8eb github.com/stretchr/testify v1.9.0 + github.com/test-go/testify v1.1.4 github.com/urfave/cli/v2 v2.25.5 github.com/whyrusleeping/cbor-gen v0.1.1 github.com/yugabyte/pgx/v5 v5.5.3-yb-2 @@ -282,7 +283,6 @@ require ( github.com/sirupsen/logrus v1.9.2 // indirect github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect - github.com/test-go/testify v1.1.4 // indirect github.com/triplewz/poseidon v0.0.0-20230828015038-79d8165c88ed // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasttemplate v1.0.1 // indirect From 24a5e3b42764e5c881bb0c498b8c1013025db267 Mon Sep 17 00:00:00 2001 From: "Andrew Jackson (Ajax)" Date: Mon, 29 Jul 2024 17:28:26 -0500 Subject: [PATCH 6/6] rm forest --- .circleci/config.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index ec3da228d..ae548eb39 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -231,9 +231,6 @@ jobs: - image: yugabytedb/yugabyte:2.21.0.1-b1 command: bin/yugabyted start --daemon=false name: yugabyte - - image: ghcr.io/chainsafe/forest:latest - command: forest /bin/bash - name: forest resource_class: << parameters.resource_class >> steps: - install-ubuntu-deps