Skip to content

Commit e67178a

Browse files
committed
test: add concurrent read test
1 parent ffaf9a0 commit e67178a

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

.github/workflows/clipboard.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
- uses: actions/setup-go@v2
3434
with:
3535
stable: 'false'
36-
go-version: '1.16.0-rc1'
36+
go-version: '1.16.0'
3737

3838
- name: TestLinux
3939
run: |

clipboard_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,26 @@ func TestClipboardMultipleWrites(t *testing.T) {
9999
}
100100
}
101101

102+
func TestClipboardConcurrentRead(t *testing.T) {
103+
// This test check that concurrent read/write to the clipboard does
104+
// not cause crashes on some specific platform, such as macOS.
105+
done := make(chan bool, 2)
106+
go func() {
107+
defer func() {
108+
done <- true
109+
}()
110+
clipboard.Read(clipboard.FmtText)
111+
}()
112+
go func() {
113+
defer func() {
114+
done <- true
115+
}()
116+
clipboard.Read(clipboard.FmtImage)
117+
}()
118+
<-done
119+
<-done
120+
}
121+
102122
func BenchmarkClipboard(b *testing.B) {
103123

104124
b.Run("text", func(b *testing.B) {

0 commit comments

Comments
 (0)