Skip to content

Commit aad2232

Browse files
committed
fix tests for Windows
1 parent 24d5555 commit aad2232

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

extensions/cache/cache_test.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"fmt"
1010
"os"
1111
"path/filepath"
12+
"runtime"
1213
"sync"
1314
"testing"
1415
"time"
@@ -93,6 +94,7 @@ func TestExport(t *testing.T) {
9394

9495
// Export should write the in-memory cache to the accessor and touch the timestamp file
9596
lastWrite := time.Time{}
97+
touched := false
9698
for i := 0; i < 3; i++ {
9799
s := fmt.Sprint(i)
98100
*ic = fakeInternalCache{data: []byte(s)}
@@ -103,9 +105,19 @@ func TestExport(t *testing.T) {
103105
f, err := os.Stat(p)
104106
require.NoError(t, err)
105107
mt := f.ModTime()
106-
require.NotEqual(t, lastWrite, mt, "Export should have updated the timestamp")
108+
109+
// Two iterations of this loop can run within one unit of system time on Windows, leaving the
110+
// modtime apparently unchanged even though Export updated it. On Windows we therefore skip
111+
// the strict test, instead requiring only that the modtime change once during this loop.
112+
if runtime.GOOS != "windows" {
113+
require.NotEqual(t, lastWrite, mt, "Export didn't update the timestamp")
114+
}
115+
if mt != lastWrite {
116+
touched = true
117+
}
107118
lastWrite = mt
108119
}
120+
require.True(t, touched, "Export didn't update the timestamp")
109121
}
110122

111123
func TestFilenameCompat(t *testing.T) {
@@ -189,8 +201,9 @@ func TestReplace(t *testing.T) {
189201
require.Empty(t, ic)
190202

191203
// Replace should read data from the accessor (external cache) into the in-memory cache, observing the timestamp file
192-
_, err = os.Create(p)
204+
f, err := os.Create(p)
193205
require.NoError(t, err)
206+
require.NoError(t, f.Close())
194207
for i := uint8(0); i < 4; i++ {
195208
ec.data = []byte{i}
196209
err = c.Replace(ctx, &ic, cache.ReplaceHints{})

0 commit comments

Comments
 (0)