servicetalk-testing
Skill1k starsChanged 2 months agoApache-2.0View on GitHub
How tests are written in the ServiceTalk repository: assertion style, naming, the reactive and transport test harnesses, test doubles, and what to verify before claiming a change is done. Use when adding or changing any test, or when diagnosing a failing, flaky, or hanging test.
Trending
Quiet since October.about the whole repository
Who's talking about apple/servicetalk
- A Hacker News story“ServiceTalk”Hacker News · Nov 5, 2019 · 7 points
- A Hacker News story“Apple open sources ServiceTalk, a JVM network application framework”Hacker News · Nov 13, 2019 · 3 points
- A Hacker News story“Apple open sources ServiceTalk framework”Hacker News · Nov 6, 2019 · 3 points
- A Hacker News story“ServiceTalk – A networking framework that evolves with your application”Hacker News · May 19, 2022 · 2 points
- A Hacker News story“ServiceTalk – A networking framework that evolves with your application”Hacker News · Mar 24, 2023 · 1 points
The biggest 5 of 46 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 46
Talked about on GitHub and Hacker News (46 times).
On GitHub · 41
- Oct 18, 2021Plugin is not present in alternativePaths, leading to false cache hits — google/protobuf-gradle-plugin1 reaction · 1 comment
- Oct 5, 2026Bump io.servicetalk:servicetalk-concurrent-reactivestreams from 0.42.66 to 0.42.67 — akarnokd/akarnokd-misc0 reactions
- Sep 1, 2026Bump io.servicetalk:servicetalk-bom from 0.42.65 to 0.42.66 — sullis/servicetalk-playground0 reactions
- Aug 31, 2026Bump io.servicetalk:servicetalk-concurrent-reactivestreams from 0.42.65 to 0.42.66 — akarnokd/akarnokd-misc0 reactions
- Aug 13, 2026servicetalk-grpc-netty-0.42.56.jar: 1 vulnerabilities (highest severity is: 7.5) - autoclosed — jgeraigery/servicetalk0 reactions · 1 comment
36 more on GitHub
- Aug 1, 2026Bump io.servicetalk:servicetalk-bom from 0.42.61 to 0.42.65 — sullis/servicetalk-playground0 reactions
- Jul 27, 2026Upgrade ServiceTalk version to 0.42.65 — apple/rules_servicetalk0 reactions · 1 comment
- Jul 23, 2026Bump io.servicetalk:servicetalk-concurrent-reactivestreams from 0.42.64 to 0.42.65 — akarnokd/akarnokd-misc0 reactions
- Jun 1, 2026Bump io.servicetalk:servicetalk-bom from 0.42.61 to 0.42.64 — sullis/servicetalk-playground0 reactions · 1 comment
- May 14, 2026Bump io.servicetalk:servicetalk-concurrent-reactivestreams from 0.42.63 to 0.42.64 — akarnokd/akarnokd-misc0 reactions
- Apr 27, 2026Bump io.servicetalk:servicetalk-concurrent-reactivestreams from 0.42.46 to 0.42.63 — akarnokd/akarnokd-misc0 reactions
- Mar 1, 2026Bump io.servicetalk:servicetalk-bom from 0.42.61 to 0.42.63 — sullis/servicetalk-playground0 reactions · 1 comment
- Feb 1, 2026Bump io.servicetalk:servicetalk-bom from 0.42.61 to 0.42.62 — sullis/servicetalk-playground0 reactions · 1 comment
- Jan 1, 2026Bump io.servicetalk:servicetalk-bom from 0.42.60 to 0.42.61 — sullis/servicetalk-playground0 reactions
- Oct 2, 2025Intend to contribute `kotlinx-coroutines-servicetalk` module — Kotlin/kotlinx.coroutines0 reactions · 9 comments
- Oct 1, 2025Bump io.servicetalk:servicetalk-bom from 0.42.59 to 0.42.60 — sullis/servicetalk-playground0 reactions
- Sep 1, 2025Bump io.servicetalk:servicetalk-bom from 0.42.57 to 0.42.59 — sullis/servicetalk-playground0 reactions
- Aug 1, 2025Bump io.servicetalk:servicetalk-bom from 0.42.57 to 0.42.58 — sullis/servicetalk-playground0 reactions · 1 comment
- Jul 1, 2025Bump io.servicetalk:servicetalk-bom from 0.42.56 to 0.42.57 — sullis/servicetalk-playground0 reactions
- Jun 4, 2025Plugin request for Buf Schema Registry - apple/servicetalk — bufbuild/plugins0 reactions
- May 1, 2025Bump io.servicetalk:servicetalk-bom from 0.42.55 to 0.42.56 — sullis/servicetalk-playground0 reactions
- Apr 1, 2025Bump io.servicetalk:servicetalk-bom from 0.42.54 to 0.42.55 — sullis/servicetalk-playground0 reactions
- Mar 1, 2025Bump io.servicetalk:servicetalk-bom from 0.42.52 to 0.42.54 — sullis/servicetalk-playground0 reactions
- Feb 26, 2025Expose experimental settings for dns — line/armeria0 reactions · 2 comments
- Feb 1, 2025Bump io.servicetalk:servicetalk-bom from 0.42.52 to 0.42.53 — sullis/servicetalk-playground0 reactions · 1 comment
- Nov 1, 2024Bump io.servicetalk:servicetalk-bom from 0.42.48 to 0.42.50 — sullis/servicetalk-playground0 reactions
- Sep 25, 2024Increased modularity of netty-codec is backward incompatible change for 4.1 — netty/netty0 reactions · 8 comments
- Sep 1, 2024Bump io.servicetalk:servicetalk-bom from 0.42.44 to 0.42.48 — sullis/servicetalk-playground0 reactions · 1 comment
- Aug 1, 2024Bump io.servicetalk:servicetalk-bom from 0.42.44 to 0.42.47 — sullis/servicetalk-playground0 reactions · 1 comment
- Jul 1, 2024Bump io.servicetalk:servicetalk-bom from 0.42.44 to 0.42.46 — sullis/servicetalk-playground0 reactions · 1 comment
- Jun 26, 2024Bump io.servicetalk:servicetalk-concurrent-reactivestreams from 0.42.45 to 0.42.46 — akarnokd/akarnokd-misc0 reactions
- Jun 13, 2024Bump io.servicetalk:servicetalk-concurrent-reactivestreams from 0.42.44 to 0.42.45 — akarnokd/akarnokd-misc0 reactions
- May 15, 2024Bump io.servicetalk:servicetalk-concurrent-reactivestreams from 0.42.43 to 0.42.44 — akarnokd/akarnokd-misc0 reactions
- Apr 18, 2024Bump io.servicetalk:servicetalk-concurrent-reactivestreams from 0.42.42 to 0.42.43 — akarnokd/akarnokd-misc0 reactions
- Feb 22, 2024Bump io.servicetalk:servicetalk-concurrent-reactivestreams from 0.42.41 to 0.42.42 — akarnokd/akarnokd-misc0 reactions
- Jan 22, 2024Bump io.servicetalk:servicetalk-concurrent-reactivestreams from 0.42.40 to 0.42.41 — akarnokd/akarnokd-misc0 reactions
- Dec 15, 2023Bump io.servicetalk:servicetalk-concurrent-reactivestreams from 0.42.38 to 0.42.40 — akarnokd/akarnokd-misc0 reactions
- Nov 17, 2023Bump io.servicetalk:servicetalk-concurrent-reactivestreams from 0.42.38 to 0.42.39 — akarnokd/akarnokd-misc0 reactions · 1 comment
- Oct 12, 2023Bump io.servicetalk:servicetalk-concurrent-reactivestreams from 0.42.37 to 0.42.38 — akarnokd/akarnokd-misc0 reactions
- Sep 25, 2023Bump io.servicetalk:servicetalk-concurrent-reactivestreams from 0.42.36 to 0.42.37 — akarnokd/akarnokd-misc0 reactions
- Nov 25, 2020Bump servicetalk.ver from 0.25.0 to 0.34.0 — Fernthedev/ServerRestAPI0 reactions
On Hacker News · 5
- Nov 5, 2019ServiceTalk7 points
- Nov 13, 2019Apple open sources ServiceTalk, a JVM network application framework3 points
- Nov 6, 2019Apple open sources ServiceTalk framework3 points
- May 19, 2022ServiceTalk – A networking framework that evolves with your application2 points · 1 comment
- Mar 24, 2023ServiceTalk – A networking framework that evolves with your application1 point
In this repository5 other files it gives its agents.
- AGENTS.mdAGENTS.md
- servicetalk-grpc-netty/AGENTS.mdAGENTS.md
- servicetalk-http-netty/AGENTS.mdAGENTS.md
- servicetalk-transport-netty-internal/AGENTS.mdAGENTS.md
- servicetalk-commit-messagesSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
15 rules. About 0 are common, 5 are distinctive, and 10 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
10
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 13
All tests live in src/test/java and end in Test.java.
- Distinctive: line 41
Add one only for a test that deliberately runs long, such as a race-detection loop of hundreds of iterations.
- Very specific: line 49
Put the subject in assertThat and let the matcher describe the expectation.
- Very specific: line 117
If a test's only contract really is "this does not throw", say so in the name (...DoesNotThrow) so the next reader knows it is deliberate.
- Very specific: line 134
Never depend on shared static mutable state, and be careful with process-global switches such as AsyncContext.disable().
- Distinctive: line 156
Do that before writing.
- Very specific: line 209
Mock
SubscriberandSubscriptioninterfaces: when you only need to assert which callbacks fired. - Very specific: line 212
Use
TestPublisher/TestSingle/TestCompletable: when you need to *drive* signals rather than count them. - Very specific: line 214
Write a shared fake: when several tests need the same double.
- Very specific: line 222
Always pass an explicit name.
- Very specific: line 235
Use @MethodSource with Named.of(...) when the arguments are objects whose toString() would be unreadable.
- Distinctive: line 246
Do not use an assumption to gate on a system property — that is the one case to avoid, and pruning a matrix as above stays fine.
- Distinctive: line 261
Prefer deriving expected values from the production source of truth.
- Very specific: line 266
Test dependencies are declared per module and an unused or undeclared one fails ./gradlew quality.
- Distinctive: line 277
Add whichever of these matches the harness you picked:
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Writing tests in ServiceTalk
ServiceTalk is a JVM networking framework (HTTP/1.1, HTTP/2, gRPC) built on
Netty over an asynchronous Publisher/Single/Completable core. Its test
conventions are not the JUnit defaults. Follow this file rather than
general Java testing habits.
All tests live in src/test/java and end in Test.java. There is no separate
integration-test source set, Gradle task, or @Tag — a test that binds a real
socket sits beside one that drives an EmbeddedChannel. The only real choice
is which harness you need. See "Pick your harness" below.
1. Rules for every test
- Java 8 by default. Most modules compile test code with
--release 8, so novar, noList.of/Map.of/Set.of, no text blocks, noOptional.isEmpty(). UseArrays.asList(...),Collections.singletonList(...), and explicit types. Some modules opt into a higher level — thejersey3-*,jersey4-*and*jakarta*variants,servicetalk-concurrent-jdkflow, andservicetalk-data-jackson3. Check the module'sbuild.gradleforsourceCompatibilitybefore you use a newer API. - Apache 2.0 header at the top of every new file, with the current year.
See
AGENTS.mdfor the exact block. - Name the class
<ClassUnderTest>Test, package-private, in the same package as the class under test. - Name methods
<methodUnderTest><Condition><ExpectedResult>in camelCase. Noshouldprefix, no underscores. Real examples from the repo:decodeThrowsIfMoreThanMaxBytes,cancelBeforeSetDoneClearsInterrupt,timeoutExceptionDeliveredBeforeUpstreamException. - Assert with Hamcrest —
assertThat(actual, matcher). This is the overwhelming majority style. Do not add AssertJ. - Test exceptions with
assertThrows, never try/catch plusfail(). - Do not add
@Timeout. A global default already applies to every test: 10s locally, 30s in CI (ServiceTalkLibraryPlugin.groovy,junit.jupiter.execution.timeout.default). Add one only for a test that deliberately runs long, such as a race-detection loop of hundreds of iterations. - Do not use
@Nestedor@DisplayName. Tests here are flat. There are zero@DisplayNameuses in the repo. - Never delete or disable a test to make a build pass. Fix it.
2. Assertions: bad → good
Put the subject in assertThat and let the matcher describe the expectation.
A good matcher prints what it actually got when it fails; assertTrue prints
expected: <true> but was: <false>.
| Avoid | Use |
assertTrue(list.isEmpty()) | assertThat(list, is(empty())) |
assertEquals(n, list.size()) | assertThat(list, hasSize(n)) |
assertTrue(list.contains(x)) | assertThat(list, hasItem(x)) |
assertTrue(x instanceof Foo) | assertThat(x, instanceOf(Foo.class)) |
assertEquals(expected, actual) | assertThat(actual, is(expected)) |
assertNull(x) | assertThat(x, is(nullValue())) |
assertTrue(a == b) | assertThat(a, is(sameInstance(b))) |
assertTrue(s.startsWith("x")) | assertThat(s, startsWith("x")) |
assertTrue(map.containsKey(k)) | assertThat(map, hasKey(k)) |
Standard import block:
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.jupiter.api.Assertions.assertThrows;assertTrue, assertFalse, assertNotNull, and assertThrows from
org.junit.jupiter.api.Assertions are fine for plain boolean and exception
checks. Reach for Hamcrest whenever a matcher would produce a better failure
message.
For an expected failure, use DELIBERATE_EXCEPTION, not
new RuntimeException("boom"). It is the repo-wide convention and stubs out
fillInStackTrace(), so it is cheap and produces stable output:
import static io.servicetalk.concurrent.internal.DeliberateException.DELIBERATE_EXCEPTION;
publisher.onError(DELIBERATE_EXCEPTION);
assertThat(subscriber.awaitOnError(), is(sameInstance(DELIBERATE_EXCEPTION)));To inspect a thrown exception, capture it and chain:
ExecutionException e = assertThrows(ExecutionException.class, () -> single.toFuture().get());
assertThat(e.getCause(), instanceOf(MaxMessageSizeExceededException.class));3. Every test must be able to fail
Each test must end on a real assertion — assertThat, assertThrows,
verify, or an await* that throws on the wrong signal.
Never call a boolean-returning helper and discard the result. It is an
easy mistake to make, and the test then passes whatever the code does:
// Wrong: the result is thrown away, so the test cannot fail.
areSetCookiesEqual(expected, actual);
// Right, if the helper must return a boolean.
assertTrue(areSetCookiesEqual(expected, actual));Better still, write the helper to assert internally and return void, so no
call site can forget.
If a test's only contract really is "this does not throw", say so in the name
(...DoesNotThrow) so the next reader knows it is deliberate.
4. Test classes run concurrently
junit-platform.properties (shipped in servicetalk-test-resources, which is
on the test classpath of most modules) sets:
junit.jupiter.execution.parallel.enabled = true
junit.jupiter.execution.parallel.mode.default = same_thread
junit.jupiter.execution.parallel.mode.classes.default = same_threadMethods within one class run on one thread, but separate test classes run at the same time. Therefore:
- Never depend on shared static mutable state, and be careful with
process-global switches such as
AsyncContext.disable(). - Bind servers with
localAddress(0)so the OS picks a free port. Never hardcode one. - Close everything you open. An unclosed
ServerContextorIoExecutordoes not fail your test — it leaks a socket or a thread pool into a test class running beside yours, which then looks flaky for no reason.
The same applies to any thread state you set deliberately. If your test interrupts a thread, clear the flag before you return — see "Interrupts" in references/reactive-sources.md.
5. Pick your harness
| What you are testing | Harness | Read |
A Publisher/Single/Completable operator | TestPublisher + TestPublisherSubscriber | references/reactive-sources.md, then TimeoutPublisherTest |
A codec or Netty ChannelHandler | EmbeddedChannel — no sockets | references/transport-and-netty.md, then HttpRequestEncoderTest |
| A filter, client, or server end to end | Real bound server plus a real client | references/transport-and-netty.md, then BlockingStreamingInputStreamTest |
| A plain value type or utility | A flat JUnit test, no harness | RoundRobinSelectorTest |
Reading the named exemplar is faster and more accurate than reading prose. Do that before writing.
6. Waiting for asynchronous results
.toFuture().get() with no timeout is the norm here. That is deliberate:
the global test timeout fires, and
TimeoutTracingInfoExtension (registered automatically for every test) dumps
every thread's stack just before JUnit interrupts the test. Do not add timed
overloads to match a different codebase's style.
Never sleep and then assert on an asynchronous side effect. A sleep encodes a guess about timing, and the guess fails on a loaded CI machine. Wait for the signal itself:
// Wrong: passes or fails depending on machine load.
Thread.sleep(100);
assertThat(exporter.spans(), hasSize(1));
// Right: waits for the thing you actually care about.
assertTrue(spanLatch.await(DEFAULT_TIMEOUT_SECONDS, SECONDS));
assertThat(exporter.spans(), hasSize(1));DEFAULT_TIMEOUT_SECONDS comes from TestTimeoutConstants and already tracks
the global timeout, so a bounded wait never outlives the test:
import static io.servicetalk.concurrent.internal.TestTimeoutConstants.DEFAULT_TIMEOUT_SECONDS;A CountDownLatch, a BlockingQueue, or an observer callback all work. When
the signal is inherently untimed — a weak reference being enqueued, for
instance — poll it in a retry loop bounded by DEFAULT_TIMEOUT_SECONDS rather
than sleeping once.
For errors raised on a thread other than the test thread, collect them and assert at the end:
import static io.servicetalk.test.resources.TestUtils.assertNoAsyncErrors;
Queue<Throwable> errors = new LinkedBlockingQueue<>();
// ... callbacks add to errors ...
assertNoAsyncErrors(errors);7. Test doubles
Both Mockito styles are in active use — static mock(Foo.class) alone, and
@Mock with @ExtendWith(MockitoExtension.class). Either is acceptable. Use
static mock() for a one-off, @Mock when several tests share the field.
- Mock
SubscriberandSubscriptioninterfaces when you only need to assert which callbacks fired.mock(SingleSource.Subscriber.class)and friends are idiomatic here. - Use
TestPublisher/TestSingle/TestCompletablewhen you need to drive signals rather than count them. - Write a shared fake when several tests need the same double. See
TestLoadBalancedConnectioninservicetalk-loadbalancer— a small interface with a static factory that pre-stubs the common methods. Mockito.spyis rare. Prefer a mock or a fake, and reach for a spy only to observe calls on a real collaborator you cannot otherwise inject.
8. Parameterized tests
Always pass an explicit name. Without one the test report shows only an
index, so a CI failure tells you a case failed but not which one:
@ParameterizedTest(name = "{displayName} [{index}] {arguments}")
@EnumSource(TimerBehaviorParam.class)
void dataAndTimeout(TimerBehaviorParam params) { ... }
@ParameterizedTest(name = "{displayName} [{index}]: unhealthy={0} failOpen={1}")
@CsvSource({"true,true", "true,false", "false,true", "false,false"})
void singleInactiveHostWithoutConnections(boolean unhealthy, boolean failOpen) { ... }Use @MethodSource with Named.of(...) when the arguments are objects whose
toString() would be unreadable.
Prune invalid combinations with an assumption and a message. This is idiomatic here, and common across the protocol-matrix tests:
assumeFalse(api.isAggregated(), "This test asserts behavior only for streaming use-cases");
assumeTrue(protocol == HTTP_1);Do not use an assumption to gate on a system property — that is the one case to avoid, and pruning a matrix as above stays fine. A failed assumption aborts the test and reports as skipped, so the coverage silently disappears when the property flips.
9. What to test, and what to skip
Skip: getters and setters, toString, equals/hashCode without logic, and
null-input branches in packages annotated @ElementsAreNonnullByDefault
(which Checkstyle requires in every package-info.java, so it always holds).
Do test every validation throw. Grep the class under test for throw new
and make sure each site has a matching assertThrows. Builder setters that
validate their arguments are the most commonly missed case.
Prefer deriving expected values from the production source of truth. Iterate the real enum rather than hardcoding a list that will drift.
10. Adding a test to a module
Test dependencies are declared per module and an unused or undeclared one fails
./gradlew quality. The common lines, exactly as written in this repo:
testImplementation enforcedPlatform("org.junit:junit-bom:$junit5Version")
testImplementation "org.junit.jupiter:junit-jupiter-api"
testImplementation "org.junit.jupiter:junit-jupiter-params"
testImplementation "org.hamcrest:hamcrest:$hamcrestVersion"
testImplementation "org.mockito:mockito-core:$mockitoCoreVersion"Add whichever of these matches the harness you picked:
| Line | Gives you |
testImplementation project(":servicetalk-test-resources") | DefaultTestCerts, TestUtils.assertNoAsyncErrors, the shared log4j2 config |
testImplementation testFixtures(project(":servicetalk-concurrent-internal")) | DeliberateException, TestTimeoutConstants, TimeoutTracingInfoExtension |
testImplementation testFixtures(project(":servicetalk-concurrent-api")) | TestPublisher, TestSingle, TestCompletable, ExecutorExtension, BlockingTestUtils |
testImplementation project(":servicetalk-concurrent-test-internal") | TestPublisherSubscriber, TestSingleSubscriber, TestCompletableSubscriber, AwaitUtils |
testImplementation testFixtures(project(":servicetalk-transport-netty-internal")) | AddressUtils, ExecutionContextExtension, EmbeddedDuplexChannel, CloseUtils |
testImplementation project(":servicetalk-buffer-netty") | Buffer allocators for tests |
11. Before you claim done
./gradlew :servicetalk-<module>:test --tests "io.servicetalk.<pkg>.<Class>Test"
./gradlew :servicetalk-<module>:test
./gradlew :servicetalk-<module>:quality- A hanging test is diagnosed from the
TimeoutTracingInfoExtensionthread dump printed just before the timeout fires. Read it before guessing. - To see wire-level traffic:
./gradlew :servicetalk-http-netty:test -Dservicetalk.logger.wireLogLevel=DEBUG. Other keys areh2FrameLogLevel,lifecycleObserverLogLevel, androotLevel. - To check whether the lines you changed are covered:
./gradlew :servicetalk-<module>:jacocoTestReport, then openservicetalk-<module>/build/reports/jacoco/test/html/index.html. Coverage is a prompt to think, not a target — the repo sets no threshold.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

