-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmutex_test.go
More file actions
92 lines (73 loc) · 1.63 KB
/
Copy pathmutex_test.go
File metadata and controls
92 lines (73 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package hot
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestMutexMock(t *testing.T) {
is := assert.New(t)
t.Parallel()
// Test that mutexMock implements rwMutex interface
var _ rwMutex = (*mutexMock)(nil)
// Create a mutexMock instance
mock := mutexMock{}
// Test that all methods can be called without panicking
is.NotPanics(func() {
mock.Lock()
})
is.NotPanics(func() {
mock.Unlock()
})
is.NotPanics(func() {
mock.RLock()
})
is.NotPanics(func() {
mock.RUnlock()
})
// Test that multiple calls don't cause issues
is.NotPanics(func() {
mock.Lock()
mock.Lock()
mock.Unlock() //nolint:staticcheck
mock.Unlock()
})
is.NotPanics(func() {
mock.RLock()
mock.RLock()
mock.RUnlock() //nolint:staticcheck
mock.RUnlock()
})
// Test mixed read/write operations
is.NotPanics(func() {
mock.Lock()
mock.Unlock() //nolint:staticcheck
mock.RLock()
mock.RUnlock() //nolint:staticcheck
mock.Lock()
mock.Unlock() //nolint:staticcheck
})
}
func TestMutexMockConcurrency(t *testing.T) {
is := assert.New(t)
t.Parallel()
mock := mutexMock{}
// Test that multiple goroutines can call the mock methods without issues
done := make(chan bool, 10)
for i := 0; i < 10; i++ {
go func() {
defer func() { done <- true }()
// Call all methods multiple times
for j := 0; j < 100; j++ {
mock.Lock()
mock.Unlock() //nolint:staticcheck
mock.RLock()
mock.RUnlock() //nolint:staticcheck
}
}()
}
// Wait for all goroutines to complete
for i := 0; i < 10; i++ {
<-done
}
// If we get here without panicking, the test passes
is.True(true) //nolint:testifylint
}