@@ -1425,17 +1425,19 @@ func (s *contextTestSuite) TestAllocateTimerIDsLocked_WhenDomainIsActiveActiveUs
14251425}
14261426
14271427func (s * contextTestSuite ) TestAllocateTimerIDsLocked_WhenTaskTimestampBeforeReadCursorAdjustsTimestamp () {
1428+ s .mockResource .TimeSource = clock .NewMockedTimeSourceAt (time .Now ())
1429+ testTimeNow := s .mockResource .TimeSource .Now ()
14281430 domainCacheEntry := s .setupAllocateTimerIDsTest ()
14291431
14301432 // Set up scheduled task max read level map with read cursor ahead of task timestamp
14311433 // Use the actual current cluster name from cluster metadata
14321434 currentCluster := s .context .GetClusterMetadata ().GetCurrentClusterName ()
1433- readCursor := time . Date ( 2025 , 1 , 1 , 13 , 0 , 0 , 0 , time .UTC )
1435+ readCursor := testTimeNow . Add ( time .Second )
14341436 s .context .scheduledTaskMaxReadLevelMap [currentCluster ] = readCursor
14351437
14361438 task := s .createMockTimerTask (createMockTimerTaskParams {
14371439 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
14391441 DomainID : testDomainID ,
14401442 WorkflowID : testWorkflowID ,
14411443 RunID : "test-run-id" ,
@@ -1457,6 +1459,41 @@ func (s *contextTestSuite) TestAllocateTimerIDsLocked_WhenTaskTimestampBeforeRea
14571459 "Adjusted timestamp should match expected adjusted time" )
14581460}
14591461
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+
14601497func (s * contextTestSuite ) TestAllocateTimerIDsLocked_WhenClusterManagerLookupFailsReturnsError () {
14611498 // Create active-active domain cache entry
14621499 domainInfo := & persistence.DomainInfo {ID : testDomainID }
0 commit comments