Skip to content

Commit

Permalink
Reproduce race in go/vt/throttle
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
  • Loading branch information
timvaillancourt committed Jun 6, 2024
1 parent 88e075b commit b83f057
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions go/vt/throttler/throttler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,16 @@ limitations under the License.
package throttler

import (
"context"
"runtime"
"testing"
"time"

"github.com/stretchr/testify/require"

"vitess.io/vitess/go/vt/discovery"
"vitess.io/vitess/go/vt/proto/query"
"vitess.io/vitess/go/vt/proto/topodata"
)

// The main purpose of the benchmarks below is to demonstrate the functionality
Expand Down Expand Up @@ -398,3 +403,52 @@ func TestThreadFinished_SecondCallPanics(t *testing.T) {
}()
throttler.ThreadFinished(0)
}

func TestThrottlerMaxLag(t *testing.T) {
fc := &fakeClock{}
throttler, _ := newThrottlerWithClock("test", "queries", 1, 1, ReplicationLagModuleDisabled, fc.now)
defer throttler.Close()

ctx, cancel := context.WithCancel(context.Background())

go func(ctx context.Context, throttler *Throttler) {
for {
select {
case <-ctx.Done():
return
default:
for _, tabletType := range []topodata.TabletType{
topodata.TabletType_REPLICA,
topodata.TabletType_RDONLY,
} {
throttler.MaxLag(tabletType)
}
}
}
}(ctx, throttler)

go func(cancel context.CancelFunc, throttler *Throttler) {
defer cancel()
for _, tabletType := range []topodata.TabletType{
topodata.TabletType_REPLICA,
topodata.TabletType_RDONLY,
} {
cache := throttler.maxReplicationLagModule.lagCacheByType(tabletType)
cache.add(replicationLagRecord{
time: time.Now(),
TabletHealth: discovery.TabletHealth{
Serving: true,
Stats: &query.RealtimeStats{
ReplicationLagSeconds: 5,
},
Tablet: &topodata.Tablet{
Hostname: t.Name(),
PortMap: map[string]int32{
"test": 15999,
},
},
},
})
}
}(cancel, throttler)
}

0 comments on commit b83f057

Please sign in to comment.