Skip to content

Commit ba2d51b

Browse files
committed
core: initialize fd pipes in tests and increase queue size in test
1 parent 7f10d6a commit ba2d51b

File tree

2 files changed

+26
-25
lines changed

2 files changed

+26
-25
lines changed

core/internal/server/wayland/manager_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

1414
func TestManager_ActorSerializesOutputStateAccess(t *testing.T) {
1515
m := &Manager{
16-
cmdq: make(chan cmd, 128),
16+
cmdq: make(chan cmd, 8192),
1717
stopChan: make(chan struct{}),
1818
}
1919

core/internal/server/wlcontext/context_test.go

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,29 @@ import (
55
"testing"
66

77
"github.com/stretchr/testify/assert"
8+
"golang.org/x/sys/unix"
89
)
910

10-
func TestSharedContext_ConcurrentPostNonBlocking(t *testing.T) {
11-
sc := &SharedContext{
12-
cmdQueue: make(chan func(), 256),
11+
func newTestSharedContext(t *testing.T, queueSize int) *SharedContext {
12+
t.Helper()
13+
fds := make([]int, 2)
14+
if err := unix.Pipe(fds); err != nil {
15+
t.Fatalf("failed to create test pipe: %v", err)
16+
}
17+
t.Cleanup(func() {
18+
unix.Close(fds[0])
19+
unix.Close(fds[1])
20+
})
21+
return &SharedContext{
22+
cmdQueue: make(chan func(), queueSize),
1323
stopChan: make(chan struct{}),
24+
wakeR: fds[0],
25+
wakeW: fds[1],
1426
}
27+
}
28+
29+
func TestSharedContext_ConcurrentPostNonBlocking(t *testing.T) {
30+
sc := newTestSharedContext(t, 256)
1531

1632
var wg sync.WaitGroup
1733
const goroutines = 100
@@ -33,10 +49,7 @@ func TestSharedContext_ConcurrentPostNonBlocking(t *testing.T) {
3349
}
3450

3551
func TestSharedContext_PostQueueFull(t *testing.T) {
36-
sc := &SharedContext{
37-
cmdQueue: make(chan func(), 2),
38-
stopChan: make(chan struct{}),
39-
}
52+
sc := newTestSharedContext(t, 2)
4053

4154
sc.Post(func() {})
4255
sc.Post(func() {})
@@ -47,11 +60,8 @@ func TestSharedContext_PostQueueFull(t *testing.T) {
4760
}
4861

4962
func TestSharedContext_StartMultipleTimes(t *testing.T) {
50-
sc := &SharedContext{
51-
cmdQueue: make(chan func(), 256),
52-
stopChan: make(chan struct{}),
53-
started: false,
54-
}
63+
sc := newTestSharedContext(t, 256)
64+
sc.started = true
5565

5666
var wg sync.WaitGroup
5767
const goroutines = 10
@@ -70,10 +80,7 @@ func TestSharedContext_StartMultipleTimes(t *testing.T) {
7080
}
7181

7282
func TestSharedContext_DrainCmdQueue(t *testing.T) {
73-
sc := &SharedContext{
74-
cmdQueue: make(chan func(), 256),
75-
stopChan: make(chan struct{}),
76-
}
83+
sc := newTestSharedContext(t, 256)
7784

7885
counter := 0
7986
for i := 0; i < 10; i++ {
@@ -89,21 +96,15 @@ func TestSharedContext_DrainCmdQueue(t *testing.T) {
8996
}
9097

9198
func TestSharedContext_DrainCmdQueueEmpty(t *testing.T) {
92-
sc := &SharedContext{
93-
cmdQueue: make(chan func(), 256),
94-
stopChan: make(chan struct{}),
95-
}
99+
sc := newTestSharedContext(t, 256)
96100

97101
sc.drainCmdQueue()
98102

99103
assert.Len(t, sc.cmdQueue, 0)
100104
}
101105

102106
func TestSharedContext_ConcurrentDrainAndPost(t *testing.T) {
103-
sc := &SharedContext{
104-
cmdQueue: make(chan func(), 256),
105-
stopChan: make(chan struct{}),
106-
}
107+
sc := newTestSharedContext(t, 256)
107108

108109
var wg sync.WaitGroup
109110

0 commit comments

Comments
 (0)