Skip to content

Commit

Permalink
closedts/sidetransport: speed up a test
Browse files Browse the repository at this point in the history
Make a test send larger proto messages, to fill network buffers fasters.
Makes a difference under race.

Release note: None
Release justification: Tests only
  • Loading branch information
andreimatei committed Mar 5, 2021
1 parent 5de5b2e commit cfde2bb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/kv/kvserver/closedts/sidetransport/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ func (s *Sender) UnregisterLeaseholder(
func (s *Sender) publish(ctx context.Context) hlc.ClockTimestamp {
s.trackedMu.Lock()
defer s.trackedMu.Unlock()
log.VEventf(ctx, 2, "side-transport publishing a new message")
log.VEventf(ctx, 4, "side-transport generating a new message")

msg := &ctpb.Update{
NodeID: s.nodeID,
Expand Down
22 changes: 19 additions & 3 deletions pkg/kv/kvserver/closedts/sidetransport/sender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,24 @@ func TestRPCConnUnblocksOnStopper(t *testing.T) {
}}))
defer stopper.Stop(ctx)

// Add a leaseholder that can close, in order to establish a connection to n2.
r1 := newMockReplica(15, 1, 2)
s.RegisterLeaseholder(ctx, r1, 1)
// Add leaseholders that can close, in order to establish a connection to n2.
// We add many of them, and we'll increment their LAIs periodically such that
// all messages need to explicitly mention all of them, in order to get large
// messages. This speeds up the test, since the large messages make the sender
// block quicker.
const numReplicas = 10000
replicas := make([]*mockReplica, numReplicas)
for i := 0; i < numReplicas; i++ {
replicas[i] = newMockReplica(roachpb.RangeID(i+1), 1, 2)
s.RegisterLeaseholder(ctx, replicas[i], 1 /* leaseSeq */)
}

incrementLAIs := func() {
for _, r := range replicas {
r.lai++
}
}

s.publish(ctx)
require.Len(t, s.conns, 1)

Expand All @@ -430,6 +445,7 @@ func TestRPCConnUnblocksOnStopper(t *testing.T) {
case <-ch:
// As soon as the conn send a message, publish another update to cause
// the conn to send another message.
incrementLAIs()
s.publish(ctx)
case <-time.After(100 * time.Millisecond):
// The conn hasn't sent anything in a while. It must be blocked on Send.
Expand Down

0 comments on commit cfde2bb

Please sign in to comment.