Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP Ensure the cli's test commands work | waiting PR 121 #119

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down Expand Up @@ -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
8 changes: 5 additions & 3 deletions cmd/curio/test-cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
snadrus marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return xerrors.Errorf("reading result from harmony_test: %w", err)
}
Expand All @@ -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)
}
Expand All @@ -161,14 +161,15 @@ 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)
}

log.Infof("Tasks found in harmony_task: %v", found)
}
}
fmt.Println("All tasks completed successfully")
return nil
},
}
Expand Down Expand Up @@ -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
},
}
3 changes: 2 additions & 1 deletion harmony/harmonydb/harmonydb.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"math/rand"
"net"
"os"
"regexp"
"sort"
"strconv"
Expand Down Expand Up @@ -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
)
}

Expand Down
16 changes: 9 additions & 7 deletions itests/curio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)

Expand Down
46 changes: 46 additions & 0 deletions itests_with_chain/cli_post_test.go
Original file line number Diff line number Diff line change
@@ -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 {
snadrus marked this conversation as resolved.
Show resolved Hide resolved
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")
}
}