Skip to content

Commit 3f6754f

Browse files
committed
chore(tests): restore TestConcurrentTokenManagerOperations
1 parent c950c66 commit 3f6754f

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

manager/token_manager_test.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,21 +1457,25 @@ func TestConcurrentTokenManagerOperations(t *testing.T) {
14571457
select {
14581458
case tokenCh <- t:
14591459
default:
1460+
// Channel full, ignore
14601461
}
14611462
},
14621463
onErrorFunc: func(err error) {
14631464
select {
14641465
case errorCh <- err:
14651466
default:
1467+
// Channel full, ignore
14661468
}
14671469
},
14681470
}
14691471

14701472
// Choose operation based on a pattern
1473+
// Using modulo for a deterministic pattern that exercises all operations
14711474
opType := j % 3
14721475

14731476
switch opType {
14741477
case 0:
1478+
// Start the token manager with a new listener
14751479
closeFunc, err := tm.Start(listener)
14761480

14771481
if err != nil {
@@ -1485,12 +1489,15 @@ func TestConcurrentTokenManagerOperations(t *testing.T) {
14851489
continue
14861490
}
14871491

1492+
// Store the closer for later cleanup
14881493
closerKey := fmt.Sprintf("closer-%d-%d", routineID, j)
14891494
closers.Store(closerKey, closeFunc)
14901495

1496+
// Simulate some work
14911497
time.Sleep(time.Duration(500-rand.Intn(400)) * time.Millisecond)
14921498

14931499
case 1:
1500+
// Get current token
14941501
token, err := tm.GetToken(false)
14951502
if err != nil {
14961503
select {
@@ -1502,12 +1509,15 @@ func TestConcurrentTokenManagerOperations(t *testing.T) {
15021509
select {
15031510
case tokenCh <- token:
15041511
default:
1512+
// Channel full, ignore
15051513
}
15061514
}
15071515

15081516
case 2:
1517+
// Close a previously created token manager listener
1518+
// This simulates multiple subscriptions being created and destroyed
15091519
closers.Range(func(key, value interface{}) bool {
1510-
if j%10 > 7 {
1520+
if j%10 > 7 { // Only close some of the time based on a pattern
15111521
closeFunc := value.(StopFunc)
15121522
if err := closeFunc(); err != nil {
15131523
if err != ErrTokenManagerAlreadyStopped {
@@ -1520,7 +1530,7 @@ func TestConcurrentTokenManagerOperations(t *testing.T) {
15201530
}
15211531

15221532
closers.Delete(key)
1523-
return false
1533+
return false // stop after finding one to close
15241534
}
15251535
return true
15261536
})
@@ -1538,6 +1548,8 @@ func TestConcurrentTokenManagerOperations(t *testing.T) {
15381548
// Use a timeout to detect deadlocks
15391549
select {
15401550
case <-doneCh:
1551+
// All operations completed successfully
1552+
t.Log("All concurrent operations completed successfully")
15411553
case <-time.After(30 * time.Second):
15421554
t.Fatal("test timed out, possible deadlock detected")
15431555
}
@@ -1596,6 +1608,14 @@ func TestConcurrentTokenManagerOperations(t *testing.T) {
15961608
totalOps := startCount + getTokenCount + closeCount
15971609
expectedOps := int32(numGoroutines * numConcurrentOps)
15981610

1611+
// Report operation counts
1612+
t.Logf("Concurrent test summary:")
1613+
t.Logf("- Total operations executed: %d (expected: %d)", totalOps, expectedOps)
1614+
t.Logf("- Start operations: %d (with %d errors)", startCount, len(startErrors))
1615+
t.Logf("- GetToken operations: %d (with %d errors, %d successful)",
1616+
getTokenCount, len(getTokenErrors), len(tokens))
1617+
t.Logf("- Close operations: %d (with %d errors)", closeCount, len(closeErrors))
1618+
15991619
// Some errors are expected due to concurrent operations
16001620
// but we should have received tokens successfully
16011621
assert.Equal(t, expectedOps, totalOps, "All operations should be accounted for")
@@ -1604,6 +1624,7 @@ func TestConcurrentTokenManagerOperations(t *testing.T) {
16041624
// Verify the token manager still works after all the concurrent operations
16051625
finalListener := &concurrentTestTokenListener{
16061626
onNextFunc: func(t *token.Token) {
1627+
// Just verify we get a token - don't use assert within this callback
16071628
if t == nil {
16081629
panic("Final token should not be nil")
16091630
}

0 commit comments

Comments
 (0)