Skip to content

Commit eeed7e8

Browse files
committed
lockedfile: update to Go tip as of March 2023
As of commit 7a21f799a5ac23d3e191a106d71af9b8f65279fd, which is crucially right before https://go.dev/cl/476917, as then internal/filelock starts using Go 1.21's errors.ErrUnsupported. We still want to support Go 1.19 and 1.20 for a while. The only change besides the import path rewriting is to drop testenv, which was only used for MustHaveExec and Command. Note that we no longer need to worry about unix build tags, as we now require Go 1.19 or later.
1 parent a4f6fab commit eeed7e8

File tree

7 files changed

+25
-52
lines changed

7 files changed

+25
-52
lines changed

lockedfile/internal/filelock/filelock_fcntl.go

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// license that can be found in the LICENSE file.
44

55
//go:build aix || (solaris && !illumos)
6-
// +build aix solaris,!illumos
76

87
// This code implements the filelock API using POSIX 'fcntl' locks, which attach
98
// to an (inode, process) pair rather than a file descriptor. To avoid unlocking

lockedfile/internal/filelock/filelock_other.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build !aix && !darwin && !dragonfly && !freebsd && !linux && !netbsd && !openbsd && !plan9 && !solaris && !windows
6-
// +build !aix,!darwin,!dragonfly,!freebsd,!linux,!netbsd,!openbsd,!plan9,!solaris,!windows
5+
//go:build !unix && !windows
76

87
package filelock
98

lockedfile/internal/filelock/filelock_plan9.go

-37
This file was deleted.

lockedfile/internal/filelock/filelock_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// license that can be found in the LICENSE file.
44

55
//go:build !js && !plan9
6-
// +build !js,!plan9
76

87
package filelock_test
98

lockedfile/internal/filelock/filelock_unix.go

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// license that can be found in the LICENSE file.
44

55
//go:build darwin || dragonfly || freebsd || illumos || linux || netbsd || openbsd
6-
// +build darwin dragonfly freebsd illumos linux netbsd openbsd
76

87
package filelock
98

lockedfile/internal/filelock/filelock_windows.go

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// license that can be found in the LICENSE file.
44

55
//go:build windows
6-
// +build windows
76

87
package filelock
98

lockedfile/lockedfile_test.go

+24-9
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,32 @@ func mustBlock(t *testing.T, desc string, f func()) (wait func(*testing.T)) {
4343
close(done)
4444
}()
4545

46+
timer := time.NewTimer(quiescent)
47+
defer timer.Stop()
4648
select {
4749
case <-done:
4850
t.Fatalf("%s unexpectedly did not block", desc)
49-
return nil
51+
case <-timer.C:
52+
}
53+
54+
return func(t *testing.T) {
55+
logTimer := time.NewTimer(quiescent)
56+
defer logTimer.Stop()
5057

51-
case <-time.After(quiescent):
52-
return func(t *testing.T) {
58+
select {
59+
case <-logTimer.C:
60+
// We expect the operation to have unblocked by now,
61+
// but maybe it's just slow. Write to the test log
62+
// in case the test times out, but don't fail it.
5363
t.Helper()
54-
select {
55-
case <-time.After(probablyStillBlocked):
56-
t.Fatalf("%s is unexpectedly still blocked after %v", desc, probablyStillBlocked)
57-
case <-done:
58-
}
64+
t.Logf("%s is unexpectedly still blocked after %v", desc, quiescent)
65+
66+
// Wait for the operation to actually complete, no matter how long it
67+
// takes. If the test has deadlocked, this will cause the test to time out
68+
// and dump goroutines.
69+
<-done
70+
71+
case <-done:
5972
}
6073
}
6174
}
@@ -242,10 +255,12 @@ locked:
242255
if _, err := os.Stat(filepath.Join(dir, "locked")); !os.IsNotExist(err) {
243256
break locked
244257
}
258+
timer := time.NewTimer(1 * time.Millisecond)
245259
select {
246260
case <-qDone:
261+
timer.Stop()
247262
break locked
248-
case <-time.After(1 * time.Millisecond):
263+
case <-timer.C:
249264
}
250265
}
251266

0 commit comments

Comments
 (0)