Skip to content

Use testing/synctest to eliminate waits in tests #528

Open
HadrienPatte wants to merge 2 commits intooracle:masterfrom
DataDog:pr/HadrienPatte/test-optimization
Open

Use testing/synctest to eliminate waits in tests #528
HadrienPatte wants to merge 2 commits intooracle:masterfrom
DataDog:pr/HadrienPatte/test-optimization

Conversation

@HadrienPatte
Copy link

pkg/csi/driver tests currently take more than 4 minutes to run and cause timeouts in CI (exit code 143, SIGTERM from runner). This is caused by 14 "timeout" sub-tests across bv_controller_test.go and fss_controller_test.go each blocking for a full testTimeout (15s) of real wall-clock time (~210s total).

These tests verify that operations correctly propagate context cancellation when a volume or attachment gets stuck. The mocks simulate an infinite page stream using a non-blocking select with a default branch, causing the caller's pagination loop to spin-wait on the CPU until the context deadline elapses in real time.

Since go 1.25, go supports using fake time to reliabily test those scenarios without having to wait for the actual timeout when running the tests. See Testing concurrent code with testing/synctest.

This PR updates those tests to use testing/synctest:

  • Update go from 1.24 to 1.25 to have testing/synctest support.
  • Wrap each affected t.Run body in synctest.Test(), so context.WithTimeout and all mock calls run under a fake clock.
  • Change the five non-blocking select { default: } branches in mock_oci_clients.go to select { case <-time.After(mockPollInterval): }, making goroutines durably block so the fake clock can advance.
  • Move the shared context.WithTimeout in fss_controller_test.go inside each t.Run (it was incorrectly shared across sub-tests in a loop).

Before:

ok      github.com/oracle/oci-cloud-controller-manager/pkg/csi/driver   231.711s

After:

ok      github.com/oracle/oci-cloud-controller-manager/pkg/csi/driver   1.933s

Result: pkg/csi/driver tests are 100x faster

Update go to 1.25, the currently used go 1.24 has stopped being
supported when go 1.26 got released in February, see [go release
policy](https://go.dev/doc/devel/release#policy).

Signed-off-by: Hadrien Patte <hadrien.patte@datadoghq.com>
`pkg/csi/driver` tests currently take more than 4 minutes to run and
cause timeouts in CI (exit code 143, SIGTERM from runner). This is
caused by 14 "timeout" sub-tests across `bv_controller_test.go` and
`fss_controller_test.go` each blocking for a full testTimeout (15s) of
real wall-clock time (~210s total).

These tests verify that operations correctly propagate context
cancellation when a volume or attachment gets stuck. The mocks simulate
an infinite page stream using a non-blocking select with a default
branch, causing the caller's pagination loop to spin-wait on the CPU
until the context deadline elapses in real time.

Since [go 1.25](https://go.dev/doc/go1.25#new-testingsynctest-package),
go supports using fake time to reliabily test those scenarios without
having to wait for the actual timeout when running the tests. See
[Testing concurrent code with testing/synctest](https://go.dev/blog/synctest).

This PR updates those tests to use `testing/synctest`:
* Update go from 1.24 to 1.25 to have `testing/synctest` support.
* Wrap each affected `t.Run` body in `synctest.Test()`, so
  `context.WithTimeout` and all mock calls run under a fake clock.
* Change the five non-blocking `select { default: }` branches in
  `mock_oci_clients.go` to
  `select { case <-time.After(mockPollInterval): }`, making goroutines
  durably block so the fake clock can advance.
* Move the shared `context.WithTimeout` in `fss_controller_test.go`
  inside each `t.Run` (it was incorrectly shared across sub-tests in a
  loop).

Before:
```
ok      github.com/oracle/oci-cloud-controller-manager/pkg/csi/driver   231.711s
```

After:
```
ok      github.com/oracle/oci-cloud-controller-manager/pkg/csi/driver   1.933s
```

Result: `pkg/csi/driver` tests are 100x faster

Signed-off-by: Hadrien Patte <hadrien.patte@datadoghq.com>
@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OCA Verified All contributors have signed the Oracle Contributor Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant