Skip to content

Commit

Permalink
lockedfile: update to Go tip as of March 2023
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mvdan committed May 15, 2023
1 parent a4f6fab commit eeed7e8
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 52 deletions.
1 change: 0 additions & 1 deletion lockedfile/internal/filelock/filelock_fcntl.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// license that can be found in the LICENSE file.

//go:build aix || (solaris && !illumos)
// +build aix solaris,!illumos

// This code implements the filelock API using POSIX 'fcntl' locks, which attach
// to an (inode, process) pair rather than a file descriptor. To avoid unlocking
Expand Down
3 changes: 1 addition & 2 deletions lockedfile/internal/filelock/filelock_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

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

package filelock

Expand Down
37 changes: 0 additions & 37 deletions lockedfile/internal/filelock/filelock_plan9.go

This file was deleted.

1 change: 0 additions & 1 deletion lockedfile/internal/filelock/filelock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// license that can be found in the LICENSE file.

//go:build !js && !plan9
// +build !js,!plan9

package filelock_test

Expand Down
1 change: 0 additions & 1 deletion lockedfile/internal/filelock/filelock_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// license that can be found in the LICENSE file.

//go:build darwin || dragonfly || freebsd || illumos || linux || netbsd || openbsd
// +build darwin dragonfly freebsd illumos linux netbsd openbsd

package filelock

Expand Down
1 change: 0 additions & 1 deletion lockedfile/internal/filelock/filelock_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// license that can be found in the LICENSE file.

//go:build windows
// +build windows

package filelock

Expand Down
33 changes: 24 additions & 9 deletions lockedfile/lockedfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,32 @@ func mustBlock(t *testing.T, desc string, f func()) (wait func(*testing.T)) {
close(done)
}()

timer := time.NewTimer(quiescent)
defer timer.Stop()
select {
case <-done:
t.Fatalf("%s unexpectedly did not block", desc)
return nil
case <-timer.C:
}

return func(t *testing.T) {
logTimer := time.NewTimer(quiescent)
defer logTimer.Stop()

case <-time.After(quiescent):
return func(t *testing.T) {
select {
case <-logTimer.C:
// We expect the operation to have unblocked by now,
// but maybe it's just slow. Write to the test log
// in case the test times out, but don't fail it.
t.Helper()
select {
case <-time.After(probablyStillBlocked):
t.Fatalf("%s is unexpectedly still blocked after %v", desc, probablyStillBlocked)
case <-done:
}
t.Logf("%s is unexpectedly still blocked after %v", desc, quiescent)

// Wait for the operation to actually complete, no matter how long it
// takes. If the test has deadlocked, this will cause the test to time out
// and dump goroutines.
<-done

case <-done:
}
}
}
Expand Down Expand Up @@ -242,10 +255,12 @@ locked:
if _, err := os.Stat(filepath.Join(dir, "locked")); !os.IsNotExist(err) {
break locked
}
timer := time.NewTimer(1 * time.Millisecond)
select {
case <-qDone:
timer.Stop()
break locked
case <-time.After(1 * time.Millisecond):
case <-timer.C:
}
}

Expand Down

0 comments on commit eeed7e8

Please sign in to comment.