Skip to content

test(client): make the Encrypt deadline subtest deterministic - #842

Merged
JoshVanL merged 2 commits into
dapr:mainfrom
nelson-parente:test/crypto-context-deadline-race
Oct 14, 2026
Merged

JoshVanL merged 2 commits into
dapr:mainfrom
nelson-parente:test/crypto-context-deadline-race

Conversation

@nelson-parente

Copy link
Copy Markdown
Contributor

Description

TestEncrypt/context_canceled in client/crypto_test.go is flaky. It expects codes.DeadlineExceeded but sometimes gets codes.Unknown:

Error:      Not equal:
            expected: 0x4
            actual  : 0x2
Test:       TestEncrypt/context_canceled

It failed in the Test job of #839 (job log), a PR that changes only go.mod files.

The subtest uses a 1-second deadline and a slowReader that waits delay before each byte. With delay: time.Second, the first byte reaches the sender goroutine at the same moment as the deadline. Then two goroutines in performCryptoOperation can close the response pipe first:

  • The receiver gets the DeadlineExceeded status from RecvMsg and closes the pipe with it. The test expects this error.
  • The sender returns from Read, sees ctx.Err() != nil and closes the pipe with the plain context.DeadlineExceeded. status.Code returns Unknown for that error.

io.Pipe keeps the first error, so the result depends on which goroutine runs first.

This PR sets delay: 3 * time.Second. The first byte then arrives 2 seconds after the deadline, so the receiver always closes the pipe first. The existing comment already said that reading "should take a lot longer than 1s". The subtest still takes about 1 second, because io.ReadAll returns at the deadline. The change is in the test only.

Issue reference

No issue.

Checklist

  • Code compiles correctly
  • Created/updated tests
  • Extended the documentation (not applicable)

Local checks (go1.26.4, macOS arm64):

  • Before: go test ./client -run 'TestEncrypt/context_canceled' -count=30 -v failed in 2 of 30 runs with the same expected: 0x4, actual: 0x2.
  • After: the same command passed all 60 runs. TestMain runs the suite twice (TCP and unix socket), so 30 counts give 60 runs. Before, the first pass failed and TestMain stopped after 30.
  • go test -race ./client passes. go vet ./client reports no issues, and golangci-lint run ./client/... reports the same findings with and without this change.

🤖 Generated with Claude Code

https://claude.ai/code/session_017JhKUDV9dbs5JDz2uwZqz5

TestEncrypt/context_canceled expects DeadlineExceeded. slowReader waits
before each byte, so with a 1s delay the first byte reached the sender
at the same moment as the 1s deadline. When the sender ran first, it
closed the pipe with ctx.Err(), and status.Code returned Unknown. Wait
3s before each byte, so the receiver always closes the pipe first with
the DeadlineExceeded status.

Signed-off-by: Nelson Parente <nelson_parente@live.com.pt>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017JhKUDV9dbs5JDz2uwZqz5
@nelson-parente
nelson-parente marked this pull request as ready for review October 9, 2026 11:13
@nelson-parente
nelson-parente requested review from a team as code owners October 9, 2026 11:13
JoshVanL pushed a commit that referenced this pull request Oct 11, 2026
Sets the SDK version to v1.16.0-rc.1 and pins go.mod (root and examples)
to the Dapr 1.19 release candidate line:

- github.com/dapr/dapr v1.18.0 -> v1.19.0-rc.1
- github.com/dapr/kit v0.18.1 -> v0.18.4
- github.com/dapr/durabletask-go v0.12.1 -> v0.14.2-0.20260930152504-a90f95c3898d
  (the pseudo-version at a90f95c3, the commit dapr v1.19.0-rc.1's own go.mod
  requires; v0.14.1 does not satisfy that requirement)
- go 1.26.4 -> 1.26.6

`go mod tidy` also moves go-chi/chi, go-spiffe, otel, golang.org/x/{net,sys,text},
google.golang.org/grpc and genproto/googleapis/rpc to the minimum versions the
new dapr/dapr requirement selects. No source change.

Once Dapr 1.19.0-rc.2 is tagged, the durabletask-go line needs a second pin to
that commit's own requirement (fe0e70b7, not yet tagged as of this PR).

Supersedes #839, #840 and #841, whose changes are folded into this PR and the
two commits carried over from them:

- #840 pinned `validate_examples.yaml` to runtime 1.19.0-rc.1 (carried as-is).
- #841 added the placement/scheduler log dump on example failure (carried as-is).
- #839 bumped durabletask-go to v0.14.1; this PR pins it to the runtime's own
  requirement instead, which is lower in semver but is what rc.1 actually
  pins, so v0.14.1 is not used.

Verified in a worktree off origin/main (e06de53):
- `go build ./...` and `go vet ./...` clean, root and examples modules.
- `go test ./... -count=1` (root module): all packages pass, including
  `client` (TestEncrypt/context_canceled, the flake #842 targets, did not
  flake on this run).

Signed-off-by: Nelson Parente <nelson_parente@live.com.pt>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017JhKUDV9dbs5JDz2uwZqz5
Signed-off-by: Nelson Parente <nelson_parente@live.com.pt>

@cicoyle cicoyle left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the PR, @nelson-parente! 🙌 Raising the slowReader delay so the first byte always arrives after the deadline removes the race in TestEncrypt/context_canceled, where the sender and receiver goroutines could each close the response pipe first and give Unknown instead of DeadlineExceeded. The description explains the race clearly, and the updated code comment and the before/after repeated runs make the change easy to trust ✨

Drafted with AI assistance and reviewed by me.

@codecov

codecov Bot commented Oct 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 56.71%. Comparing base (879e040) to head (3439e1b).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #842   +/-   ##
=======================================
  Coverage   56.71%   56.71%           
=======================================
  Files          52       52           
  Lines        3784     3784           
=======================================
  Hits         2146     2146           
  Misses       1483     1483           
  Partials      155      155           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@JoshVanL
JoshVanL merged commit 6489fe3 into dapr:main Oct 14, 2026
46 checks passed
@marcduiker

Copy link
Copy Markdown
Contributor

@holopin-bot @nelson-parente sdk-badge Thank you! Here's a digital badge as a small token of appreciation.

@holopin-bot

holopin-bot Bot commented Oct 16, 2026

Copy link
Copy Markdown

Congratulations @nelson-parente, the maintainer of this repository has issued you a badge! Here it is: https://holopin.io/claim/cmvao5p74000hjh04v4fp0694

This badge can only be claimed by you, so make sure that your GitHub account is linked to your Holopin account. You can manage those preferences here: https://holopin.io/account.
Or if you're new to Holopin, you can simply sign up with GitHub, which will do the trick!

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.

4 participants