diff --git a/.circleci/config.yml b/.circleci/config.yml index ac37689ee..ae548eb39 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -179,6 +179,75 @@ 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 + 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 + 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 + 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 + CURIO_HARMONYDB_HOSTS: yugabyte + LOTUS_HARMONYDB_HOSTS: yugabyte command: | mkdir -p /tmp/test-reports/<< parameters.suite >> mkdir -p /tmp/test-artifacts @@ -274,3 +343,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 82792bd0d..44c3bcc1b 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/go.mod b/go.mod index faa144ec9..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 diff --git a/go.sum b/go.sum index 985eac5d6..dc3faa9a6 100644 --- a/go.sum +++ b/go.sum @@ -1261,6 +1261,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/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 14a1eed18..ac3f53b14 100644 --- a/itests/curio_test.go +++ b/itests/curio_test.go @@ -44,6 +44,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() @@ -63,13 +71,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..3d45d5180 --- /dev/null +++ b/itests_with_chain/cli_post_test.go @@ -0,0 +1,39 @@ +package itests + +import ( + "bytes" + "io" + "os" + "os/exec" + "strconv" + "testing" + + "github.com/test-go/testify/require" + "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() + 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") + require.NoError(t, cmd.Run()) + require.Equal(t, "All tasks complete\n", cmd.Buffer.String()) +}