@@ -18,32 +18,38 @@ func TestMain(m *testing.M) {
1818}
1919
2020func TestIsStale (t * testing.T ) {
21+ // Capture time.Now() once to avoid race conditions
22+ now := time .Now ()
2123 tests := []struct {
2224 time time.Time
2325 name string
2426 expected bool
2527 }{
2628 {
2729 name : "recent PR" ,
28- time : time . Now () .Add (- 24 * time .Hour ),
30+ time : now .Add (- 24 * time .Hour ),
2931 expected : false ,
3032 },
3133 {
3234 name : "stale PR" ,
33- time : time . Now () .Add (- 91 * 24 * time .Hour ),
35+ time : now .Add (- 91 * 24 * time .Hour ),
3436 expected : true ,
3537 },
3638 {
3739 name : "exactly at threshold" ,
38- time : time . Now () .Add (- 90 * 24 * time .Hour ),
40+ time : now .Add (- 90 * 24 * time .Hour ),
3941 expected : true , // >= 90 days is stale
4042 },
4143 }
4244
4345 for _ , tt := range tests {
4446 t .Run (tt .name , func (t * testing.T ) {
4547 // isStale was inlined - test the logic directly
46- if got := tt .time .Before (time .Now ().Add (- stalePRThreshold )); got != tt .expected {
48+ // Use the same 'now' for consistency
49+ threshold := now .Add (- stalePRThreshold )
50+ got := tt .time .Before (threshold )
51+ if got != tt .expected {
52+ t .Logf ("Test time: %v, Threshold: %v, Before: %v" , tt .time , threshold , got )
4753 t .Errorf ("stale check = %v, want %v" , got , tt .expected )
4854 }
4955 })
0 commit comments