Skip to content
This repository was archived by the owner on May 6, 2024. It is now read-only.

Commit dee1b8f

Browse files
author
Benjamin M. Schwartz
authored
Merge pull request #60 from Jigsaw-Code/bemasc-race
Fix data races in the tests
2 parents 010248d + 88fec3a commit dee1b8f

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

.github/workflows/go.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ jobs:
3434
run: go build -v ./...
3535

3636
- name: Test
37-
run: go test -v ./...
37+
run: go test -v -race -bench=. -benchtime=100ms ./...

tunnel/intra/doh/ipmap/ipmap_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"context"
1919
"errors"
2020
"net"
21+
"sync/atomic"
2122
"testing"
2223
)
2324

@@ -153,11 +154,11 @@ func TestDisconfirmMismatch(t *testing.T) {
153154
}
154155

155156
func TestResolver(t *testing.T) {
156-
flag := false
157+
var dialCount int32
157158
resolver := &net.Resolver{
158159
PreferGo: true,
159160
Dial: func(context context.Context, network, address string) (net.Conn, error) {
160-
flag = true
161+
atomic.AddInt32(&dialCount, 1)
161162
return nil, errors.New("Fake dialer")
162163
},
163164
}
@@ -166,7 +167,7 @@ func TestResolver(t *testing.T) {
166167
if !s.Empty() {
167168
t.Error("Google lookup should have failed due to fake dialer")
168169
}
169-
if !flag {
170+
if atomic.LoadInt32(&dialCount) == 0 {
170171
t.Error("Fake dialer didn't run")
171172
}
172173
}

tunnel/intra/protect/protect_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,21 @@ package protect
33
import (
44
"context"
55
"net"
6+
"sync"
67
"syscall"
78
"testing"
89
)
910

1011
// The fake protector just records the file descriptors it was given.
1112
type fakeProtector struct {
12-
Protector
13+
mu sync.Mutex
1314
fds []int32
1415
}
1516

1617
func (p *fakeProtector) Protect(fd int32) bool {
18+
p.mu.Lock()
1719
p.fds = append(p.fds, fd)
20+
p.mu.Unlock()
1821
return true
1922
}
2023

0 commit comments

Comments
 (0)