Skip to content

Conversation

@akrem-chabchoub
Copy link
Contributor

@akrem-chabchoub akrem-chabchoub commented Oct 10, 2025

Checklist

  • I have read the coding guide.
  • My change requires a documentation update, and I have done it.
  • I have added tests to cover my changes.
  • I have filled out the description and linked the related issues.

Description

  • Adopt virtual time via testing/synctest for deterministic, faster, and less flaky tests.
  • Remove sleeps/timeouts; improve goroutine leak/deadlock detection.

Files migrated to synctest

  • pkg/blocker/blocker_test.go
  • pkg/file/joiner/joiner_test.go
  • pkg/pingpong/pingpong_test.go
  • pkg/pullsync/pullsync_test.go
  • pkg/spinlock/wait_test.go
  • pkg/storageincentives/agent_test.go
  • pkg/storageincentives/soc_mine_test.go
  • pkg/storer/internal/events/subscribe_test.go
  • pkg/storer/internal/reserve/reserve_test.go
  • pkg/util/syncutil/syncutil_test.go

Open API Spec Version Changes (if applicable)

Motivation and Context (Optional)

Related Issue (Optional)

#5232

Screenshots (if appropriate):

@akrem-chabchoub akrem-chabchoub self-assigned this Oct 10, 2025
@akrem-chabchoub akrem-chabchoub changed the title test: integrate synctest in syncutil_test.go test: integrate synctest Oct 10, 2025
@akrem-chabchoub akrem-chabchoub marked this pull request as ready for review October 22, 2025 07:46
@akrem-chabchoub akrem-chabchoub added this to the v2.7.0 milestone Oct 22, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR integrates the testing/synctest package to modernize time-dependent tests across the codebase. The primary goal is to replace real time delays with virtual time control, making tests more deterministic and faster.

Key changes:

  • Wraps existing test functions with synctest.Test() to enable virtual time
  • Updates context creation from context.Background() to t.Context() for proper integration
  • Adjusts timing assertions to account for virtual time behavior (e.g., RTT can be 0)

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pkg/util/syncutil/syncutil_test.go Wrapped timeout test with synctest
pkg/storer/internal/reserve/reserve_test.go Added synctest to eviction test
pkg/storer/internal/events/subscribe_test.go Integrated synctest for event subscription test
pkg/storageincentives/soc_mine_test.go Added synctest wrapper to mining test
pkg/storageincentives/agent_test.go Wrapped agent tests with synctest and added goroutine wait
pkg/spinlock/wait_test.go Integrated synctest for spinlock timeout tests
pkg/pullsync/pullsync_test.go Added synctest to multiple pull sync protocol tests
pkg/pingpong/pingpong_test.go Updated RTT validation logic and removed Windows-specific timing workaround
pkg/file/joiner/joiner_test.go Migrated context creation and refactored redundancy tests with synctest
pkg/blocker/blocker_test.go Wrapped blocker timeout tests with synctest
pkg/api/gsoc_test.go Added blank line for formatting

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +132 to +137
}
return
}
}

assertOrder := func(t *testing.T, want, got contractCall) {
t.Helper()
if want != got {
t.Fatalf("expected call %s, got %s", want, got)
if len(contract.callsList) == 0 {
t.Fatal("expected calls but got none")
Copy link

Copilot AI Oct 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic flow is inverted: the code checks for no calls when expectedCalls is false, then returns, but then checks for no calls again when expectedCalls is true. This creates duplicate validation. Consider restructuring: move the zero-length check (line 136-138) before the !tc.expectedCalls block to avoid redundancy.

Copilot uses AI. Check for mistakes.
@bcsorvasi bcsorvasi linked an issue Oct 22, 2025 that may be closed by this pull request
@akrem-chabchoub
Copy link
Contributor Author

akrem-chabchoub commented Oct 29, 2025

Will split it to multiple PRs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use the new testing/synctest package from golang 1.25 in tests

2 participants