From 7f0577ce84a8c1bd8165ee48a0449153b3f7321a Mon Sep 17 00:00:00 2001 From: Chris Schinnerl Date: Thu, 24 Oct 2024 11:20:49 +0200 Subject: [PATCH 1/3] ci: run test in loop --- .github/workflows/test.yml | 47 +------------------------------------- 1 file changed, 1 insertion(+), 46 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 15e1c0673..5169c923d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,28 +7,7 @@ on: - master jobs: - analyze: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Lint - uses: golangci/golangci-lint-action@v3 - with: - args: --timeout=30m - - name: Jape Analyzer - uses: SiaFoundation/action-golang-analysis@HEAD - with: - analyzers: | - go.sia.tech/jape.Analyzer@master - directories: | - autopilot - bus bus/client - worker worker/client - flags: | - -japecheck.types=false test: - needs: analyze runs-on: ${{ matrix.os }} strategy: matrix: @@ -56,34 +35,10 @@ jobs: host port: 3800 mysql version: "8" mysql root password: test - - name: Test Stores - uses: n8maninger/action-golang-test@v1 - with: - args: "-race;-short;-tags=netgo" - - name: Test Stores - MySQL - if: matrix.os == 'ubuntu-latest' - uses: n8maninger/action-golang-test@v1 - env: - RENTERD_DB_URI: 127.0.0.1:3800 - RENTERD_DB_USER: root - RENTERD_DB_PASSWORD: test - with: - package: "./stores" - args: "-race;-short;-tags=netgo" - name: Test Integration uses: n8maninger/action-golang-test@v1 with: package: "./internal/test/e2e/..." - args: "-failfast;-race;-timeout=60m;-tags=netgo" - - name: Test Integration - MySQL - if: matrix.os == 'ubuntu-latest' - uses: n8maninger/action-golang-test@v1 - env: - RENTERD_DB_URI: 127.0.0.1:3800 - RENTERD_DB_USER: root - RENTERD_DB_PASSWORD: test - with: - package: "./internal/test/e2e/..." - args: "-failfast;-race;-timeout=60m;-tags=netgo" + args: "-failfast;-race;-timeout=60m;-tags=netgo;-run=TestEphemeralAccountSync$;-count=50" - name: Build run: go build -o bin/ -tags='netgo timetzdata' ./cmd/renterd From 97bfa107c16665497cdf4e73b014d2f536972610 Mon Sep 17 00:00:00 2001 From: Chris Schinnerl Date: Thu, 24 Oct 2024 13:24:15 +0200 Subject: [PATCH 2/3] worker: update account endpoint to return account and not just id --- autopilot/workerpool.go | 3 +-- internal/test/e2e/cluster_test.go | 19 +++++++++---------- worker/client/client.go | 2 +- worker/worker.go | 3 +-- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/autopilot/workerpool.go b/autopilot/workerpool.go index 54617aee9..000bc9860 100644 --- a/autopilot/workerpool.go +++ b/autopilot/workerpool.go @@ -5,7 +5,6 @@ import ( "sync" "time" - rhpv3 "go.sia.tech/core/rhp/v3" "go.sia.tech/core/types" "go.sia.tech/renterd/api" "go.sia.tech/renterd/object" @@ -13,7 +12,7 @@ import ( ) type Worker interface { - Account(ctx context.Context, hostKey types.PublicKey) (rhpv3.Account, error) + Account(ctx context.Context, hostKey types.PublicKey) (api.Account, error) Contracts(ctx context.Context, hostTimeout time.Duration) (api.ContractsResponse, error) ID(ctx context.Context) (string, error) MigrateSlab(ctx context.Context, s object.Slab, set string) error diff --git a/internal/test/e2e/cluster_test.go b/internal/test/e2e/cluster_test.go index 80a77f751..31eeeae36 100644 --- a/internal/test/e2e/cluster_test.go +++ b/internal/test/e2e/cluster_test.go @@ -1373,19 +1373,18 @@ func TestEphemeralAccountSync(t *testing.T) { cluster.sync() // ask for the account, this should trigger its creation - tt.OKAll(cluster.Worker.Account(context.Background(), hk)) + account, err := cluster.Worker.Account(context.Background(), hk) + tt.OK(err) + if account.ID != acc.ID { + t.Fatalf("account ID mismatch, expected %v got %v", acc.ID, account.ID) + } else if account.CleanShutdown || !account.RequiresSync { + t.Fatalf("account shouldn't be marked as clean shutdown or not require a sync, got %v %v", account.CleanShutdown, accounts[0].RequiresSync) + } // make sure we form a contract cluster.WaitForContracts() cluster.MineBlocks(1) - accounts = cluster.Accounts() - if len(accounts) != 1 || accounts[0].ID != acc.ID { - t.Fatal("account should exist") - } else if accounts[0].CleanShutdown || !accounts[0].RequiresSync { - t.Fatal("account shouldn't be marked as clean shutdown or not require a sync, got", accounts[0].CleanShutdown, accounts[0].RequiresSync) - } - // assert account was funded tt.Retry(100, 100*time.Millisecond, func() error { accounts = cluster.Accounts() @@ -1393,8 +1392,8 @@ func TestEphemeralAccountSync(t *testing.T) { return errors.New("account should exist") } else if accounts[0].Balance.Cmp(types.ZeroCurrency.Big()) == 0 { return errors.New("account isn't funded") - } else if accounts[0].RequiresSync { - return fmt.Errorf("account shouldn't require a sync, got %v", accounts[0].RequiresSync) + } else if !accounts[0].CleanShutdown || accounts[0].RequiresSync { + return fmt.Errorf("account should be marked as clean shutdown and not require a sync, got %v %v", accounts[0].CleanShutdown, accounts[0].RequiresSync) } return nil }) diff --git a/worker/client/client.go b/worker/client/client.go index 6a64fc31b..0063938d6 100644 --- a/worker/client/client.go +++ b/worker/client/client.go @@ -33,7 +33,7 @@ func New(addr, password string) *Client { } // Account returns the account id for a given host. -func (c *Client) Account(ctx context.Context, hostKey types.PublicKey) (account rhpv3.Account, err error) { +func (c *Client) Account(ctx context.Context, hostKey types.PublicKey) (account api.Account, err error) { err = c.c.WithContext(ctx).GET(fmt.Sprintf("/account/%s", hostKey), &account) return } diff --git a/worker/worker.go b/worker/worker.go index 074680cf2..bd95d4def 100644 --- a/worker/worker.go +++ b/worker/worker.go @@ -840,8 +840,7 @@ func (w *Worker) accountHandlerGET(jc jape.Context) { if jc.DecodeParam("hostkey", &hostKey) != nil { return } - account := rhpv3.Account(w.accounts.ForHost(hostKey).ID()) - jc.Encode(account) + jc.Encode(w.accounts.Account(hostKey)) } func (w *Worker) accountsHandlerGET(jc jape.Context) { From 831da7252b6fc818c419a02dfef649d39e4aeb6d Mon Sep 17 00:00:00 2001 From: Chris Schinnerl Date: Thu, 24 Oct 2024 13:35:30 +0200 Subject: [PATCH 3/3] Revert "ci: run test in loop" This reverts commit 7f0577ce84a8c1bd8165ee48a0449153b3f7321a. --- .github/workflows/test.yml | 47 +++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5169c923d..15e1c0673 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,7 +7,28 @@ on: - master jobs: + analyze: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Lint + uses: golangci/golangci-lint-action@v3 + with: + args: --timeout=30m + - name: Jape Analyzer + uses: SiaFoundation/action-golang-analysis@HEAD + with: + analyzers: | + go.sia.tech/jape.Analyzer@master + directories: | + autopilot + bus bus/client + worker worker/client + flags: | + -japecheck.types=false test: + needs: analyze runs-on: ${{ matrix.os }} strategy: matrix: @@ -35,10 +56,34 @@ jobs: host port: 3800 mysql version: "8" mysql root password: test + - name: Test Stores + uses: n8maninger/action-golang-test@v1 + with: + args: "-race;-short;-tags=netgo" + - name: Test Stores - MySQL + if: matrix.os == 'ubuntu-latest' + uses: n8maninger/action-golang-test@v1 + env: + RENTERD_DB_URI: 127.0.0.1:3800 + RENTERD_DB_USER: root + RENTERD_DB_PASSWORD: test + with: + package: "./stores" + args: "-race;-short;-tags=netgo" - name: Test Integration uses: n8maninger/action-golang-test@v1 with: package: "./internal/test/e2e/..." - args: "-failfast;-race;-timeout=60m;-tags=netgo;-run=TestEphemeralAccountSync$;-count=50" + args: "-failfast;-race;-timeout=60m;-tags=netgo" + - name: Test Integration - MySQL + if: matrix.os == 'ubuntu-latest' + uses: n8maninger/action-golang-test@v1 + env: + RENTERD_DB_URI: 127.0.0.1:3800 + RENTERD_DB_USER: root + RENTERD_DB_PASSWORD: test + with: + package: "./internal/test/e2e/..." + args: "-failfast;-race;-timeout=60m;-tags=netgo" - name: Build run: go build -o bin/ -tags='netgo timetzdata' ./cmd/renterd