GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [improve][test] Replace timeout waits in 11 slow, low-CPU unit-test classes by merlimat · Pull Request #27537 · apache/pulsar

Conversation

@merlimat

@merlimat merlimat commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Problem

Eleven unit-test classes take long in CI but use little CPU: they mostly wait for timeouts to run out. Measured with
JFR (park, sleep, monitor-wait and socket-read events) on the TestNG thread, on CI run 42615832291's commit, the waits
make up 95-100 % of their wall time. Four kinds of wait account for nearly all of it:

  1. Negative checks that always wait their full timeout. A receive, poll or readNext with a 2-10 s timeout
    is expected to return null.
    • MetadataStoreTableViewTest: 84 of 95 s.
    • CompactionTest: 13 tests, 67 s.
    • ReaderTest: 30 s.
  2. Expected failures that fail only when a 30 s default timeout runs out.
    • ProxyRolesEnforcementTest: two rejected subscribes, 60 s. The client retries a connection the broker rejects
      until its operation timeout.
    • CompactionTest.testBrokerRestartAfterCompaction: a subscribe to a stopped broker, 30 s.
    • TokenExpirationProduceConsumerTest: the default send timeout, 30 s.
    • LedgerUnderreplicationManagerTest.testLockCleanupAfterAmbiguousDelete(false, true): close(), 30 s.
  3. Injected delays far longer than the test needs.
    • OrphanPersistentTopicTest: 4-10 s against 2-5 s load timeouts.
    • UnAcknowledgedMessagesTimeoutTest: 2-3 s ack timeouts with 1-3 s backoffs.
    • ReplicationTopicGcTest: a 5 s GC cycle and 5 s inactivity thresholds.
    • MetadataStoreBatchingTest: a 1 s batching delay that every operation waits for.
  4. More throttled sends than the checks need. MessagePublishThrottlingTest sends 100-200 messages at 10 msg/s or
    400 bytes/s per phase.

CompactionTest.testDeleteCompactedLedgerWithSlowAck also waited 9 s on a latch that never counted down. It stubs
the deprecated sync Subscription.acknowledgeMessage, which the broker no longer calls, so the slow-ack race the test
was written for never ran.

Example

// MetadataStoreTableViewTest.notificationListeners: no tail item for a filtered key
tv.put(noListenKey, val0).join();
kv = tails.poll(3, TimeUnit.SECONDS);   // always waits the full 3 s
assertNull(kv);
// ProxyRolesEnforcementTest.testIncorrectRoles: the broker rejects the connection; the client logs
// "Could not get connection while getting partitioned topic metadata, will retry" until the 30 s operation timeout
try (PulsarClient proxyClient = createPulsarClient(pulsar.getBrokerServiceUrl(), proxyAuthParams)) {
    try {
        proxyClient.newConsumer().topic(topicName).subscriptionName(subscriptionName).subscribe();
    } catch (Exception ex) {
        exceptionOccurred = true;
    }
// CompactionTest.testDeleteCompactedLedgerWithSlowAck: the stub is never invoked
Mockito.doAnswer(...).when(subscription).acknowledgeMessage(Mockito.any(), Mockito.eq(
        CommandAck.AckType.Cumulative), Mockito.any());
compactionAckedLatch.await(9, TimeUnit.SECONDS);   // result ignored, always times out

Change

Negative checks become marker checks, keeping what they prove.

  • CompactionTest and ReaderTest publish a marker after everything the test wrote and expect it to be the next
    message:

    private <T> List<Message<T>> receiveUntilMarker(Consumer<T> consumer, Schema<T> schema, T markerValue)
            throws PulsarClientException {
        try (Producer<T> producer = pulsarClient.newProducer(schema).topic(consumer.getTopic())
                .enableBatching(false).create()) {
            producer.newMessage().key(MARKER_KEY).value(markerValue).send();
        }
        List<Message<T>> received = new ArrayList<>();
        while (true) {
            Message<T> message = consumer.receive(10, TimeUnit.SECONDS);
            assertNotNull(message, "The marker message did not arrive");
            if (MARKER_KEY.equals(message.getKey())) {
                consumer.acknowledge(message);
                return received;
            }
            received.add(message);
        }
    }

    A consumer or reader gets a topic's messages in order, and the marker comes after everything else (after the
    compaction horizon too). So any message still to come arrives before it. The marker stays on the topic, so it's used
    only for a test's last check, where the topic isn't read again. Earlier checks keep their timeouts.

  • MetadataStoreTableViewTest writes a marker key through the store and expects that key's tail item next. It goes
    through the store, not tv.put, because tv.put notifies the local table view before the store notification. The
    store hands notifications to its listeners in order on one thread, and the table view answers each one from its
    cache or with a store read, which completes in order. So a tail item caused by an earlier change is queued before
    the marker's.

    • The existing-item check needs no wait: start() returns after the fill has called the listeners.
    • testConcurrentPutGetOneKey's workers stop on the last value instead of after a 3 s idle poll.
  • These checks can only miss an unwanted message, never fail without one, and the old timed polls could miss a late
    one too.

Expected failures get short timeouts on the call that must fail.

  • ProxyRolesEnforcementTest: the two rejected clients have operationTimeout(2, SECONDS). The client that must
    succeed keeps the default.
  • CompactionTest.testBrokerRestartAfterCompaction: the subscribe to the stopped broker uses a separate client with a
    2 s operation timeout.
  • TokenExpirationProduceConsumerTest: a 5 s token, sendTimeout(2, SECONDS) and a 500 ms poll interval.
  • LedgerUnderreplicationManagerTest: the close row calls the existing @VisibleForTesting close(1, SECONDS). The
    acknowledgement is held until the test releases it, so the close times out the same way.

Shorter delays, still longer than what they must outlast.

  • OrphanPersistentTopicTest: a 1 s topic load timeout (the setting is in whole seconds) with 2 s injected delays.
    The number of injected failures doesn't change.
  • UnAcknowledgedMessagesTimeoutTest: the 1 s minimum ack timeout with backoffs of 100 → 400 ms and 100 → 900 ms.
  • ReplicationTopicGcTest: the GC runs every second; topics and replicators count as inactive after 2 s.
  • MetadataStoreBatchingTest: batchingMaxDelayMillis(50). No test asserts on timing, and the operations are queued
    within microseconds.
  • ReaderTest:
    • A positive wait loses its pollDelay(3 s).
    • The bad-URL creates use 100 ms timeouts. The IllegalArgumentException they guard against is thrown
      synchronously.

Fewer throttled messages. MessagePublishThrottlingTest sends 40 messages per phase. The broker+topic byte test
sends 30 × 80 bytes: more than twice the 800 bytes/s broker limit, so the broker-throttled phase stays under
numMessage * msgBytes per second even with the limiter's initial burst. Measured margins: 13 msg/s vs 40;
1,097 B/s vs 2,400.

The slow-ack race now runs. testDeleteCompactedLedgerWithSlowAck stubs acknowledgeMessageAsync, delays the
completion of the real ack by 500 ms, and asserts the latch.

Testing

-PtestRetryCount=0, two forks per module, macOS. Before is master c54c11d; after is 2-3 runs per class:

Class (CI job) Before After
CompactionTest (Client Impl) 146.1 s 53.7 s
MetadataStoreTableViewTest (Pulsar Metadata) 96.9 s 10.3-10.6 s
ProxyRolesEnforcementTest (Proxy) 63.9 s 7.1-7.5 s
TokenExpirationProduceConsumerTest (Client Api) 55.3 s 10.8-11.6 s
MessagePublishThrottlingTest (Client Api) 78.2 s 40.9-43.5 s
MetadataStoreBatchingTest (Pulsar Metadata) 44.8 s 8.1-8.9 s
ReplicationTopicGcTest (Broker Group 5) 58.1 s 21.3-22.5 s
ReaderTest (Client Impl) 51.7 s 19.3-19.6 s
LedgerUnderreplicationManagerTest (Pulsar Metadata) 198.9 s 168.0 s
OrphanPersistentTopicTest (Client Api) 68.4 s 37.6-38.2 s
UnAcknowledgedMessagesTimeoutTest (Client Impl) 76.4 s 58.6-60.9 s

That's about 495 s less class time per CI run. All tests pass in every run.

  • Mutation check: with the table view's path filter accepting every key, all five notificationListeners providers
    and both testInitialFill rows fail with expected [(tenant/ns/my-marker-4,0)] but found [(tenant/ns/to-be-filtered,0)].
  • testDeleteCompactedLedgerWithSlowAck passes with its latch asserted.
  • ./gradlew quickCheck passes, and the test sources of the three modules compile.
  • ReplicationTopicGcTest was run locally, before and after, with
    JAVA_TOOL_OPTIONS="-Dorg.apache.bookkeeper.conf.readsystemproperties=true -DdiskUsageThreshold=0.995 -DdiskUsageWarnThreshold=0.995". That's only because this machine's disk is over BookKeeper's 95 % threshold.

Not changed here:

  • LedgerUnderreplicationManagerTest's releaseUnderreplicatedLedger row still takes 30 s; it needs a test hook in
    the manager's main code.
  • Checks in the middle of a test keep their timeouts.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
merlimat added 4 commits November 9, 2026 16:49
@merlimat
[improve][test] Replace timeout waits in three pulsar-metadata test c…
e667ccb
…lasses

- MetadataStoreTableViewTest: the checks that no other tail item arrives
  waited 3 s each. They now write a marker key through the store and
  expect its tail item next. The existing-item check needs no wait, since
  start() returns after the fill has called the listeners. The
  concurrent-put workers stop on the last value instead of a 3 s idle poll.
- MetadataStoreBatchingTest: a 50 ms batching delay instead of 1 s, which
  every operation waited for.
- LedgerUnderreplicationManagerTest: the ambiguous-delete close row waits
  for a 1 s close timeout instead of the 30 s default.
@merlimat
[improve][test] Replace timeout waits in three Client Impl test classes
f45e328
- CompactionTest: the last "nothing else arrives" receive of 14 tests waited
  2-10 s for a null message. They now publish a marker and expect it to be
  the next message. testBrokerRestartAfterCompaction's subscribe to the
  stopped broker uses a client with a 2 s operation timeout instead of the
  default 30 s. testDeleteCompactedLedgerWithSlowAck stubbed the deprecated
  sync acknowledgeMessage, which the broker no longer calls, so its latch
  always ran out after 9 s and the slow-ack race never ran: it now stubs
  acknowledgeMessageAsync and asserts the latch.
- ReaderTest: the 10 s readNext calls expecting null after a seek now read a
  marker; no fixed 3 s poll delay before a positive condition; a 100 ms
  timeout for each create against a bad URL instead of 1 s.
- UnAcknowledgedMessagesTimeoutTest: the redelivery-timer variations use
  the 1 s minimum ack timeout and 100-900 ms backoffs instead of 2-3 s
  timeouts and 1-3 s backoffs.
@merlimat
[improve][test] Shorten the injected delays and throttled sends in th…
9e200fd
…ree Client Api test classes

- TokenExpirationProduceConsumerTest: a 5 s token instead of 20 s, a 2 s
  send timeout, so that the expected TimeoutException doesn't wait for the
  default 30 s, and a 500 ms poll interval instead of 3 s.
- OrphanPersistentTopicTest: a 1 s topic load timeout with 2 s injected
  delays instead of 2-5 s timeouts and 4-10 s delays. The delays still
  outlast the timeout, as each test needs.
- MessagePublishThrottlingTest: send 40 messages instead of 100-200 at
  10 msg/s or 400 bytes/s, and 30 instead of 40 in the broker and topic
  byte-throttling test. That's still more than twice the limit, so each
  rate check keeps its margin.
@merlimat
[improve][test] Cut the timeout waits of ProxyRolesEnforcementTest an…
c0662a1
…d ReplicationTopicGcTest

- ProxyRolesEnforcementTest: the two clients whose connection the broker
  rejects retried until the default 30 s operation timeout before the
  expected subscribe failure. They now have a 2 s operation timeout.
- ReplicationTopicGcTest: the inactive-topic GC runs every second, and
  topics and replicators count as inactive after 2 s instead of 5 s.
@merlimat merlimat added the area/test label Nov 10, 2026
codelipenghui
codelipenghui approved these changes Nov 10, 2026
View reviewed changes
@merlimat
Merge remote-tracking branch 'apache/master' into mmerli/test-thread-…
18d47cf
…wait-fixes

# Conflicts:
#	pulsar-broker/src/test/java/org/apache/pulsar/client/api/OrphanPersistentTopicTest.java
#	pulsar-broker/src/test/java/org/apache/pulsar/client/impl/MessagePublishThrottlingTest.java
codelipenghui
codelipenghui approved these changes Nov 10, 2026
View reviewed changes
@merlimat
Merge remote-tracking branch 'apache/master' into mmerli/test-thread-…
72807a7
…wait-fixes

# Conflicts:
#	pulsar-broker/src/test/java/org/apache/pulsar/client/api/TokenExpirationProduceConsumerTest.java
#	pulsar-metadata/src/test/java/org/apache/pulsar/metadata/bookkeeper/LedgerUnderreplicationManagerTest.java
#	pulsar-proxy/src/test/java/org/apache/pulsar/proxy/server/ProxyRolesEnforcementTest.java
codelipenghui
codelipenghui approved these changes Nov 10, 2026
View reviewed changes
@merlimat
merlimat merged commit b65738f into apache:master Nov 10, 2026
42 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@merlimat
merlimat deleted the mmerli/test-thread-wait-fixes branch November 10, 2026 15:08
lhotari pushed a commit that referenced this pull request Nov 11, 2026
@merlimat @lhotari
[improve][test] Replace timeout waits in 11 slow, low-CPU unit-test c…
22342e0
…lasses (#27537)

(cherry picked from commit b65738f)
@lhotari lhotari added release/5.0.2 cherry-picked/branch-5.0 labels Nov 11, 2026
@merlimat merlimat mentioned this pull request Nov 11, 2026
[fix][broker] Delete the schema and topic policies when another cluster deletes the partitioned topic metadata first during GC #27588
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@codelipenghui codelipenghui codelipenghui approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

area/test cherry-picked/branch-5.0 release/5.0.2

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@merlimat @codelipenghui @lhotari
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.