Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions platform/extension/messagequeue/mysql/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ type Params struct {
// MetricsScope for metrics collection (required)
MetricsScope tally.Scope

// OnSignal receives typed subscriber lifecycle signals (HookSignal).
// Nil in production; used by integration tests for event-driven waits.
// OnSignal lets tests wait on subscriber cycles without sleeping: one
// HookSignal per completed delivery check or ownership pass. Not for
// production: signals carry no data and are dropped while the channel is
// full (see emitSignal), so never treat one as a specific event or count them.
OnSignal chan HookSignal

// Tenants is the configured shard isolation list. Empty permits publishing
Expand Down
13 changes: 7 additions & 6 deletions platform/extension/messagequeue/mysql/subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ type subscriber struct {
subscriptions map[string]*subscription
subMu sync.Mutex

// OnSignal receives typed lifecycle signals. Nil in production.
// Consumers filter by signal type to wait for specific events.
// OnSignal receives typed lifecycle signals. Nil in production; see emitSignal.
OnSignal chan HookSignal
}

Expand Down Expand Up @@ -455,12 +454,14 @@ func NewSubscriber(logger *zap.SugaredLogger, scope tally.Scope, messageStore me
}
}

// emitSignal sends a signal on OnSignal if set. Blocks until the signal is
// received, allowing tests to synchronize by controlling when signals are drained.
// Production code does not set OnSignal, so this is a no-op outside tests.
// emitSignal drops sig while OnSignal is full: an unread hook must never stall
// a worker or the supervisor, so a receiver learns "at least one", not "every".
func (s *subscriber) emitSignal(sig HookSignal) {
if ch := s.OnSignal; ch != nil {
ch <- sig
select {
case ch <- sig:
default:
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions test/integration/extension/messagequeue/mysql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ Tests use **zero `time.Sleep` calls**. Instead, they use the subscriber's `OnSig
| `SignalDeliveryCheck` | A partition was checked for deliverable messages (including watermark advancement) |
| `SignalPartitionUpdate` | Partition ownership was evaluated (discovery, rebalance, lease renewal) |

Emission never blocks: a signal is dropped while the channel is full, so a received signal means at least one such event completed since the channel was last drained.

Signal names describe behavioral concerns, not implementation details, so they remain stable across internal refactors.

### Test helpers
Expand Down
2 changes: 0 additions & 2 deletions test/integration/extension/messagequeue/mysql/queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2321,8 +2321,6 @@ func (s *SQLQueueIntegrationSuite) TestGCReclaimsAckedRowsUnderContinuousTraffic
testMessage(fmt.Sprintf("gc-busy-%d", i), []byte("y"), partition, nil)))
delivery := receive(t, deliveryChan)
require.NoError(t, delivery.Ack(s.ctx))
// Drain signals so the worker's blocking send cannot stall the traffic loop.
drainSignals(signalCh)
}

waitForCondition(t, signalCh, func() bool {
Expand Down
Loading