8000 Fix flock_test from interrupting utils package tests by matoval · Pull Request #1314 · ansible/receptor · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix flock_test from interrupting utils package tests #1314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainer 8000 s and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions pkg/utils/flock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package utils_test
import (
"os"
"path/filepath"
"strconv"
"testing"

"github.com/ansible/receptor/pkg/utils"
Expand All @@ -26,7 +27,7 @@ func TestTryFLock(t *testing.T) {
args: args{
filename: filepath.Join(os.TempDir(), "good_flock_listener"),
},
want: &utils.FLock{0},
want: &utils.FLock{Fd: 0},
wantErr: false,
},
{
Expand Down Expand Up @@ -57,6 +58,25 @@ func TestTryFLock(t *testing.T) {
}

func TestFLock_Unlock(t *testing.T) {
f, err := os.CreateTemp("", "flock-test")
if err != nil {
t.Error(err)
}
defer os.Remove(f.Name())
defer f.Close()

var maxInt uintptr
if strconv.IntSize == 32 {
maxInt = uintptr(1<<31 - 1)
} else {
maxInt = uintptr(1<<63 - 1)
}

fd := f.Fd()
if fd > maxInt {
t.Error(err)
}

type fields struct {
Fd int
}
Expand All @@ -68,7 +88,7 @@ func TestFLock_Unlock(t *testing.T) {
{
name: "Positive",
fields: fields{
Fd: 1,
Fd: int(f.Fd()), // #nosec G115
},
wantErr: false,
},
Expand Down
0