@@ -1425,17 +1425,19 @@ func (s *contextTestSuite) TestAllocateTimerIDsLocked_WhenDomainIsActiveActiveUs
1425
1425
}
1426
1426
1427
1427
func (s * contextTestSuite ) TestAllocateTimerIDsLocked_WhenTaskTimestampBeforeReadCursorAdjustsTimestamp () {
1428
+ s .mockResource .TimeSource = clock .NewMockedTimeSourceAt (time .Now ())
1429
+ testTimeNow := s .mockResource .TimeSource .Now ()
1428
1430
domainCacheEntry := s .setupAllocateTimerIDsTest ()
1429
1431
1430
1432
// Set up scheduled task max read level map with read cursor ahead of task timestamp
1431
1433
// Use the actual current cluster name from cluster metadata
1432
1434
currentCluster := s .context .GetClusterMetadata ().GetCurrentClusterName ()
1433
- readCursor := time . Date ( 2025 , 1 , 1 , 13 , 0 , 0 , 0 , time .UTC )
1435
+ readCursor := testTimeNow . Add ( time .Second )
1434
1436
s .context .scheduledTaskMaxReadLevelMap [currentCluster ] = readCursor
1435
1437
1436
1438
task := s .createMockTimerTask (createMockTimerTaskParams {
1437
1439
Version : constants .EmptyVersion ,
1438
- Timestamp : time . Date ( 2025 , 1 , 1 , 12 , 0 , 0 , 0 , time .UTC ), // before read cursor
1440
+ Timestamp : readCursor . Add ( - time .Second ), // before read cursor
1439
1441
DomainID : testDomainID ,
1440
1442
WorkflowID : testWorkflowID ,
1441
1443
RunID : "test-run-id" ,
@@ -1457,6 +1459,41 @@ func (s *contextTestSuite) TestAllocateTimerIDsLocked_WhenTaskTimestampBeforeRea
1457
1459
"Adjusted timestamp should match expected adjusted time" )
1458
1460
}
1459
1461
1462
+ func (s * contextTestSuite ) TestAllocateTimerIDsLocked_WhenTaskTimestampBeforeNow () {
1463
+ s .mockResource .TimeSource = clock .NewMockedTimeSourceAt (time .Now ())
1464
+ testTimeNow := s .mockResource .TimeSource .Now ()
1465
+ domainCacheEntry := s .setupAllocateTimerIDsTest ()
1466
+
1467
+ // Set up scheduled task max read level map with read cursor ahead of task timestamp
1468
+ // Use the actual current cluster name from cluster metadata
1469
+ currentCluster := s .context .GetClusterMetadata ().GetCurrentClusterName ()
1470
+ readCursor := testTimeNow .Add (- 2 * time .Second ) // read cursor is in the past
1471
+ s .context .scheduledTaskMaxReadLevelMap [currentCluster ] = readCursor
1472
+
1473
+ task := s .createMockTimerTask (createMockTimerTaskParams {
1474
+ Version : constants .EmptyVersion ,
1475
+ Timestamp : readCursor .Add (- time .Second ), // before now but after read cursor
1476
+ DomainID : testDomainID ,
1477
+ WorkflowID : testWorkflowID ,
1478
+ RunID : "test-run-id" ,
1479
+ })
1480
+
1481
+ err := s .context .allocateTimerIDsLocked (domainCacheEntry , testWorkflowID , []persistence.Task {task })
1482
+
1483
+ s .NoError (err )
1484
+
1485
+ // Verify timestamp was adjusted to be after read cursor
1486
+ s .True (task .GetVisibilityTimestamp ().After (readCursor ),
1487
+ "Task timestamp should be adjusted to be after read cursor" )
1488
+
1489
+ // Verify it's the expected adjusted time (readCursor + DBTimestampMinPrecision)
1490
+ expectedTime := testTimeNow .Add (persistence .DBTimestampMinPrecision )
1491
+ actualTime := task .GetVisibilityTimestamp ()
1492
+ s .Equal (expectedTime .Truncate (persistence .DBTimestampMinPrecision ),
1493
+ actualTime .Truncate (persistence .DBTimestampMinPrecision ),
1494
+ "Adjusted timestamp should match expected adjusted time" )
1495
+ }
1496
+
1460
1497
func (s * contextTestSuite ) TestAllocateTimerIDsLocked_WhenClusterManagerLookupFailsReturnsError () {
1461
1498
// Create active-active domain cache entry
1462
1499
domainInfo := & persistence.DomainInfo {ID : testDomainID }
0 commit comments