24 Commits

Author SHA1 Message Date
Stephan Behnke
3ba31f2ac0 Add context-aware channel test helpers (#11700)
Adds generic `await.Rcv` and `await.Snd` helpers that bound blocking
channel operations by the test context and report closure or
cancellation clearly.

Replaces both previous helpers and existing unsafe channel rcv/snd
across tests.
2026-08-24 19:30:41 -07:00
Stephan Behnke
3c32027e55 Document testcontext package (#10296)
WISOTT
2026-05-16 07:56:22 +00:00
Stephan Behnke
cbb464fa98 Document historyrequire package (#10297)
WISOTT
2026-05-16 07:41:53 +00:00
Stephan Behnke
7c022fbdb2 add await.Require and await.RequireTrue (#9490)
## What changed?

Introduces `common/testing/await`, a polling-based test helper that
replaces testify's `Eventually` / `EventuallyWithT`.

## Why?

From the [package
doc](https://github.com/temporalio/temporal/blob/stephanos/all-require/common/testing/await/await.go):

```
Improvements over testify's eventually functions:

   - Misuse detection: accidentally using the real *testing.T (e.g. s.T() or
     suite assertion methods) instead of the callback's collect T is a
     common mistake. This package detects it and fails with a clear message.

   - Safer bool predicates: unlike testify's Eventually, [RequireTrue] only
     accepts func() bool, so returning false is the sole retry signal. If the
     predicate accidentally marks the real test failed, it reports that
     immediately instead of polling until timeout.

   - Timeout-aware callbacks: callbacks receive a context derived from the
     parent context and canceled when the await timeout or test deadline is
     reached, so RPCs and blocking waits can exit instead of continuing after
     the retry window has expired.

   - Panic propagation: if the condition panics (e.g. nil dereference), the
     panic is propagated immediately rather than being silently swallowed
     or retried until timeout.
     See https:github.com/stretchr/testify/issues/1810

   - Bounded goroutine lifetime: each attempt completes before the next
     starts, avoiding the overlapping-attempt data races and "panic: Fail
     in goroutine after Test has completed" crashes seen with testify's
     Eventually.
     See https:github.com/stretchr/testify/issues/1611

   - Deadlock detection: a condition that ignores t.Context() is abandoned
     after a grace period, producing a clear "does it honor t.Context()?"
     failure instead of hanging until go test -timeout.

   - Condition always runs: testify's Eventually can fail without ever
     running the condition due to a timer/ticker race with short timeouts.
     This package runs the condition immediately on the first iteration.
     See https://github.com/stretchr/testify/issues/1652
```

The upstream fix
([testify#1657](https://github.com/stretchr/testify/pull/1657)) aims to
address several of these but has been open since Oct 2024 without
merging.

## How did you test it?
- [ ] built
- [ ] run locally and tested manually
- [x] covered by existing tests
- [x] added new unit test(s)
- [ ] added new functional test(s)

## Potential risks

The biggest downside is that it adds more code that we own. But apart
from any unknown bugs, this package should rarely/never change.
2026-05-15 21:55:32 +00:00
Fred Tzeng
daa9bcc97c added docs on protorequire.ProtoEqual in testing.md (#10255)
## What changed?
Added a short protorequire package subsection to
docs/development/testing.md documenting protorequire.ProtoEqual and the
new protorequire.IgnoreFields option, with a minimal usage example.

## Why?
Follow-up to PR #9937. Without a doc entry, the new IgnoreFields helper
is undiscoverable and contributors will keep reaching for the verbose
cmp.Diff pattern.


## How did you test it?
- [X] built
- [ ] run locally and tested manually
- [ ] covered by existing tests
- [ ] added new unit test(s)
- [ ] added new functional test(s)
2026-05-13 17:36:20 -07:00
Stephan Behnke
c30f4f8937 Ban assert.X in favor of require.X (#9871)
## What changed?

Add lint rule that flags all `assert.*` and `protoassert.*` calls (with
an exclusion for assert.CollectT which is needed for EventuallyWithT
callbacks).

## Why?

Codify and enforce best practice.

## How did you test it?
- [ ] built
- [x] run locally and tested manually
- [ ] covered by existing tests
- [ ] added new unit test(s)
- [ ] added new functional test(s)

Added an invalid suite at
da7b125ea4 (diff-2c57794cee9b7afaa5f182010e066cb377afb52c58043c2f2554b8e44b6cd47e)
and it showed:

<img width="2155" height="496" alt="Screenshot 2026-04-08 at 12 19
51 PM"
src="https://github.com/user-attachments/assets/5e569662-d520-4325-9d24-d09624ab8164"
/>


(https://github.com/temporalio/temporal/actions/runs/24153673025/job/70487178675?pr=9871#step:4:251)
2026-04-08 12:56:07 -07:00
Stephan Behnke
b1b14ea8cd parallelsuite (#9536)
## What changed?

Added `parallelsuite` package to provide an alternative to testify's
suite.

**For reviewer: Use "Hide Whitespace" to make the diff smaller.**

## Why?

1. **Parallel by default**: all test methods and subtests run in
parallel automatically
2. **IDE support**: GoLand run gutters, navigation, and test discovery
work on Test* methods
4. **Misuse detection**: guard catches mixing assertions with Run(),
both directions, at runtime
5. **Type-safe subtests**: `s.Run` callbacks receive the concrete suite
type, so suite helpers are available
6. **No shared state**: each test method and subtest gets its own fresh
copy
  
## How did you test it?
- [ ] built
- [ ] run locally and tested manually
- [x] covered by existing tests
- [x] added new unit test(s)
- [ ] added new functional test(s)
2026-03-30 18:39:49 +00:00
Sean Kane
9030019c6a tests: write debug level logs to a file (#9608)
## What changed?
Functional tests write debug-level logs to a file rather than inline in
the job. Info and above are still visible and the debug logs are
available for download at the end of each test job.

## Why?
Debug level logs make parsing the functional test run logs very
difficult, sometimes too large to even download the logs. This makes
debugging flaky test runs even more difficult.

## How did you test it?
- [ ] built
- [ ] run locally and tested manually
- [ ] covered by existing tests
- [ ] added new unit test(s)
- [ ] added new functional test(s)
- [X] manually verified in CI

## Potential risks
Minimal, debug logs are still available to download and parse. If there
are logs that are missing for debugging we should move those from
`debug` to `info` level in the future
2026-03-23 21:12:18 +00:00
Sean Kane
29c8bb23fa Add a timeout to functional tests (#9218)
## What changed?
Add a default 90s timeout to individual tests using the
`testcore.NewEnv` for setup. Tests should use the `context.Context`
returned from `testcore.NewEnv(...)` to fail early when a test exceeds
the timeout.

## Why?
Go only allows to set a timeout for an entire test run via `go test`,
but a single test case can make the entire run be stuck for the full
test timeout time. This change will make those tests exit early speeding
up the dev process.

## How did you test it?
- [ ] built
- [X] run locally and tested manually
- [X] covered by existing tests
- [ ] added new unit test(s)
- [ ] added new functional test(s)

## Potential risks
Test change only, could introduce flakes if tests did not have previous
context timeouts.

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Medium Risk**
> Touches shared test infrastructure and changes how contexts/timeouts
are created and propagated across functional tests, which could
introduce new test flakes or premature cancellations if timeouts are too
aggressive.
> 
> **Overview**
> Functional tests created via `testcore.NewEnv` now get a *test-scoped*
timeout context (default **90s**, configurable via
`TEMPORAL_TEST_TIMEOUT` or per-test `testcore.WithTimeout`) that is
canceled on timeout and fails the test during cleanup.
> 
> `testcore.NewContext` is updated to optionally derive from a parent
context, and key functional tests are migrated to pass
`s.Context()`/`env.Context()` into RPC calls and
`context.WithTimeout(...)` to respect cancellations. Linting/docs are
updated to discourage `context.Background()` in tests and document the
new timeout knob.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
98852a5e43. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
2026-03-10 16:20:45 +00:00
Stephan Behnke
6d446b92bf Add testhooks package documentation (#9373) 2026-02-21 02:49:36 +00:00
Stephan Behnke
4ad1daa5c8 Customizable serialization (#8426)
## What changed?

Added `TEMPORAL_TEST_DATA_ENCODING` to change DataBlob encoding from
"proto3" to "json".

## Why?

Observability and debugging. The ability to see payloads decoded in
debugger and OTEL traces is valuable.

## How did you test it?
- [ ] built
- [ ] run locally and tested manually
- [ ] covered by existing tests
- [ ] added new unit test(s)
- [x] added new functional test(s)

## Potential risks

End users should never use this. The env var name therefore includes
`TEST_`.
2026-02-18 09:16:35 -08:00
Stephan Behnke
4a2e88a173 Parallelize integration tests (#9292)
## What changed?

Made integration tests run in parallel.

## Why?

Before: ~8min
[[run](https://github.com/temporalio/temporal/actions/runs/21930252400/job/63333789136#step:7:1)]
🐢
After: ~3m
[[run](https://github.com/temporalio/temporal/actions/runs/22114061618/job/63917852614?pr=9292)]
🐰

## How did you test it?
- [ ] built
- [ ] run locally and tested manually
- [x] covered by existing tests
- [ ] added new unit test(s)
- [ ] added new functional test(s)

## Potential risks

They are not known to be flaky; and anecdotally all passed on the first
run.
2026-02-18 09:13:26 -08:00
Stephan Behnke
26a2a22e74 Deprecate FunctionalTestBase (#9140)
## What changed?

1. add lint rule to not use FunctionalTestBase for new functional tests.
2. basic documentation for new `TestEnv` alternative approach

## Why?

Enforce policy for new tests while migrating existing ones.

## How did you test it?
- [ ] built
- [ ] run locally and tested manually
- [x] covered by existing tests
- [ ] added new unit test(s)
- [ ] added new functional test(s)
2026-02-05 01:13:17 +00:00
Stephan Behnke
f5bfe42239 Parallel Workflow Update Tests (#8811)
## What changed?

Migrated `TestWorkflowUpdateSuite` away from testify's `Suite`; enabling
parallel test execution.

**How it works**

- a test invokes `testcore.NewEnv(t)` to obtain a new `TestEnv`
- `TestEnv` sets `t.Parallel()` (_intentionally not giving a way to opt
out!_)
- `TestEnv` obtains a test cluster from `clusterPool` (_or blocks if all
are in-use right now_)
- env var `TEMPORAL_TEST_SHARED_CLUSTERS` controls size of the pool
- if a test relies on APIs like InjectHook, a dedicated cluster is used
to prevent overlap
- env var `TEMPORAL_TEST_DEDICATED_CLUSTERS` controls number of
dedicated clusters

**testify suites**

Existing test suites are limited by the same dedicated cluster pool to
prevent creating too many clusters.

**Database connections**

SQLite setup for TestEnv-based func tests (ie only
TestWorkflowUpdateSuite so far) has been changed to a file-based
approach since that supports much better concurrency due to its WAL that
an in-memory SQLite database does not support.

Connection limits for other databases were also raised due to connection
errors.

**Planned follow-ups**

- Migrating the other testify suites should be fairly straight-forward
with the use of AI agents.
- Reduce need for dedicated clusters by leveraging isolated
namespace-per-test more.
- Eliminate all `time.Sleep`s.
- Tweak test cluster pool behavior.

## Why?

1. **Local speedup**: benchmarks show a ~50% speed increase (36.1s →
16.6s) for `TestWorkflowUpdateSuite`.

5. **Namespace isolation**: every test runs in its own namespace. This
greatly reduces the risk of (accidental) collisions and also reduces the
need to craft unique identifiers such as for task queues and workflow
IDs.

6. **Deprecate testify suites**: Long-term strategy to remove use of
testify suites in functional tests (one reason being their inability to
run tests within a suite in parallel).

## How did you test it?
- [ ] built
- [ ] run locally and tested manually
- [x] covered by existing tests
- [ ] added new unit test(s)
- [ ] added new functional test(s)

## Potential Issues

1. Logs become less useful since there is more interleaving of tests. 
2. Higher resource consumption: it requires more concurrent connections
to databases and shows higher memory consumption (see 3 and 4). This
could cause some short-term instability on CI. Note that some other PRs
were merged to add mechanics for monitoring memory usage much better;
which will help here.
4. Until all functional tests are converted, there is an imbalance in
test cluster creation: migrated tests use the shared pool while current
tests create one cluster each. Especially given the fact that some tests
don't allow for test cluster sharing as they use non-parallelizable
actions such as `InjectHook` or dynamic config overrides. With some more
effort the number of these can be reduced.
7. Setup of test clusters was designed around the idea of short-lived
clusters, one per suite. But when re-using them for longer, some of the
assumptions don't hold anymore and increase memory usage. There's a band
aid in place to limit how often a test cluster can be used before it's
torn down. A long-term solution requires some design changes to how test
clusters are started/used/torn down.
8. If there are certain cross-namespace issues or bugs that affect
multiple tests, it might be harder to identify the root cause now.
However; the existing test re-runs should at least mitigate these
short-term.

---------

Co-authored-by: Dan Davison <dandavison7@gmail.com>
2026-01-24 04:08:49 +00:00
Stephan Behnke
33faf7e12f panic test hooks if not enabled (#8726)
## What changed?

Changed use of `testhooks`'s `Set` to be runtime error instead of
compile time error.

It still ensures that the default impl (used in `go build` artifacts
without `test_dep` tag) is the noop impl.

## Why?

When running a functional test via plain `go test` it will fail, as the
`test_dep` build flag is required. It is required to prevent
accidentally using the default/noop implementation of the `testhooks`
package which allows injecting custom behavior into production code from
tests.

But requiring `test_dep` to run any test adds friction: CLI invocations
need to specify it manually, editor setups need to be adjusted, AI
agents need to be instructed. That's a high price to pay for a test
helper that is used fairly sparsely.

## How did you test it?
- [ ] built
- [x] run locally and tested manually
- [x] covered by existing tests
- [x] added new unit test(s)
- [ ] added new functional test(s)


Functional test without testhook:
```
% go test ./tests -run "OwnershipLostErrorSuite" -count=1 .
ok  	go.temporal.io/server/tests	7.062s
```

Functional test with testhook and build tag:
```
% go test ./tests -run "TestUpdateWorkflowSuite" -tags test_dep -count=1 .
ok  	go.temporal.io/server/tests	36.975s
```

Functional test with testhook but no build tag:
```
% go test ./tests -run "TestUpdateWorkflowSuite" -count=1 .
...
noop_impl.go:39: test panicked: testhooks.Set called but TestHooks are not enabled: use -tags=test_dep when running `go test`
                    goroutine 33293 [running]:
                    runtime/debug.Stack()
...
FAIL
FAIL	go.temporal.io/server/tests	57.128s
FAIL
```
2025-12-09 17:43:36 +00:00
Fred Tzeng
9a1fe784f7 Reduced log level of failed Nexus requests originating from worker (#8306)
## What changed?
- Reduced log level of failed Nexus requests originating from worker to
debug level.
- Updated CONTRIBUTING.md and testing.md to reflect current status and
to include IDE debugging.
- Added failure source setting to worker in nexus handler when dispatch
context deadline exceeded.

## Why?
- Today we log an error for every request, which pollutes server logs
and is inconsistent with activity and workflow task failures. We don't
want to completely lose visibility into these errors since some of the
errors can originate internally and may be tricky to debug.
- We've missed spots in setting worker failure source in the nexus
handler
- The docs are a bit outdated, and it's also helpful to have IDE
specific debugging instructions.

## How did you test it?
- [X] built
- [X] run locally and tested manually
- [X] covered by existing tests
- [ ] added new unit test(s)
- [ ] added new functional test(s)

## Ticket
[OSS-4548](https://temporalio.atlassian.net/browse/OSS-4548)



[OSS-4548]:
https://temporalio.atlassian.net/browse/OSS-4548?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ

---------

Co-authored-by: Roey Berman <roey.berman@gmail.com>
2025-09-11 13:41:29 -07:00
Stephan Behnke
fb863dc43f Explain test build tags and env variables (#7991)
## What changed?

Added documentation for test-related build tags and env variables.

## Why?

So help developers with their test setup.
2025-08-20 18:19:02 -07:00
Stephan Behnke
76e74178f2 Increase OTEL_BSP_SCHEDULE_DELAY (#7520)
## What changed?
<!-- Describe what has changed in this PR -->

Increased OTEL_BSP_SCHEDULE_DELAY from 0 to 100ms.

## Why?
<!-- Tell your future self why have you made these changes -->

Zero is too aggressive and leads to too much CPU usage.

## How did you test it?
<!-- How have you verified this change? Tested locally? Added a unit
test? Checked in staging env? -->

## Potential risks
<!-- Assuming the worst case, what can be broken when deploying this
change to production? -->

## Documentation
<!-- Have you made sure this change doesn't falsify anything currently
stated in `docs/`? If significant
new behavior is added, have you described that in `docs/`? -->

## Is hotfix candidate?
<!-- Is this PR a hotfix candidate or does it require a notification to
be sent to the broader community? (Yes/No) -->
2025-03-25 08:21:42 -07:00
Stephan Behnke
b609189e36 Upload code coverage (#7262)
## What changed?
<!-- Describe what has changed in this PR -->

Fixed code coverage reporting.
## Why?
<!-- Tell your future self why have you made these changes -->

We haven't reported code coverage in over a year.

 It stopped working when we moved away from Buildkite.

## How did you test it?
<!-- How have you verified this change? Tested locally? Added a unit
test? Checked in staging env? -->

Checkout https://app.codecov.io/gh/temporalio/temporal

There's no data for main ("master") yet, though, until we merge.

I'll also leave the README coveralls badge there for now.

## Potential risks
<!-- Assuming the worst case, what can be broken when deploying this
change to production? -->

## Documentation
<!-- Have you made sure this change doesn't falsify anything currently
stated in `docs/`? If significant
new behavior is added, have you described that in `docs/`? -->

## Is hotfix candidate?
<!-- Is this PR a hotfix candidate or does it require a notification to
be sent to the broader community? (Yes/No) -->
2025-03-13 10:03:12 -07:00
Stephan Behnke
e04b9d79a2 OTEL test docs (#7449)
## What changed?
<!-- Describe what has changed in this PR -->
Document how to use OTEL in tests.
2025-03-11 10:25:18 -07:00
Stephan Behnke
a0d0d13f4b Describe softassert (#7426)
## What changed?
<!-- Describe what has changed in this PR -->

Explain use of `softassert` package.
2025-03-06 01:14:07 +00:00
Alex Shtin
7ac04aa033 Refactor: remove key parameter from testvar methods (#7040)
## What changed?
<!-- Describe what has changed in this PR -->
Remove `key` parameter from `testvar` methods.

## Why?
<!-- Tell your future self why have you made these changes -->
It turn out to be confusing for people on how to use optional `key`
parameter. @bergundy got a great idea to remove this parameter and use
different instance of `tv` when more than one entity is needed.

## How did you test it?
<!-- How have you verified this change? Tested locally? Added a unit
test? Checked in staging env? -->
Run all tests. Refactoring affects test code only.

## Potential risks
<!-- Assuming the worst case, what can be broken when deploying this
change to production? -->
No risks.

## Documentation
<!-- Have you made sure this change doesn't falsify anything currently
stated in `docs/`? If significant
new behavior is added, have you described that in `docs/`? -->
Yes, updated testing docs.

## Is hotfix candidate?
<!-- Is this PR a hotfix candidate or does it require a notification to
be sent to the broader community? (Yes/No) -->
No.
2025-01-09 16:38:53 -08:00
Stephan Behnke
991a038b6a Include taskpoller in test guidelines (#6959)
## What changed?
<!-- Describe what has changed in this PR -->

Added new taskpoller to project's testing guidelines.

## Why?
<!-- Tell your future self why have you made these changes -->

To recommend this behavior to newcomers.

## How did you test it?
<!-- How have you verified this change? Tested locally? Added a unit
test? Checked in staging env? -->

## Potential risks
<!-- Assuming the worst case, what can be broken when deploying this
change to production? -->

## Documentation
<!-- Have you made sure this change doesn't falsify anything currently
stated in `docs/`? If significant
new behavior is added, have you described that in `docs/`? -->

## Is hotfix candidate?
<!-- Is this PR a hotfix candidate or does it require a notification to
be sent to the broader community? (Yes/No) -->
2025-01-08 12:05:54 -08:00
Stephan Behnke
80ec9635f0 Testing docs (#6005)
## What changed?
<!-- Describe what has changed in this PR -->

Create new `testing.md` with test-specific developer guidance.

It's still very short, happy to add anything else now if there is any -
or just grow it over time.

## Why?
<!-- Tell your future self why have you made these changes -->

To document testing patterns and agreements.

## How did you test it?
<!-- How have you verified this change? Tested locally? Added a unit
test? Checked in staging env? -->

## Potential risks
<!-- Assuming the worst case, what can be broken when deploying this
change to production? -->

## Documentation
<!-- Have you made sure this change doesn't falsify anything currently
stated in `docs/`? If significant
new behavior is added, have you described that in `docs/`? -->

## Is hotfix candidate?
<!-- Is this PR a hotfix candidate or does it require a notification to
be sent to the broader community? (Yes/No) -->
2024-05-29 10:25:12 -07:00