Atlas › Test

TestLock_Low_Fail

Exact test identity: go.temporal.io/server/common/locks/TestPriorityMutexSuite/TestLock_Low_Fail

Package
go.temporal.io/server/common/locks
Suite / test hierarchy
TestPriorityMutexSuite/TestLock_Low_Fail
Test
TestLock_Low_Fail
Introduced at
priority_mutex_impl.go ×1 Frontier kind: Joint frontier
Covered ranges
8
Covered lines
41
Covered files
2

Covered source

Expand a file to inspect source; the > gutter marks covered lines.

go.temporal.io/server/common/locks/priority_mutex_impl.go 30 covered LOC · 6 ranges

Open complete file

29 var _ PriorityMutex = (*PriorityMutexImpl)(nil)
30
31 > func NewPriorityMutex() *PriorityMutexImpl { priority_mutex_impl.go
32 > lock := &sync.Mutex{}
33 > syncCV := NewConditionVariable(lock)
34 > asyncCV := NewConditionVariable(lock)
35 > return &PriorityMutexImpl{
36 > locker: lock,
37 > highCV: syncCV,
38 > lowCV: asyncCV,
39 > highWait: 0,
40 > lowWait: 0,
41 >
42 > lockState: PriorityMutexStateUnlocked,
43 > }
44 > }
45
46 // LockHigh try to lock with high priority, use LockHigh / UnlockHigh pair to lock / unlock
69 func (c *PriorityMutexImpl) LockLow(
70 ctx context.Context,
71 > ) error { priority_mutex_impl.go
72 > c.locker.Lock()
73 > defer c.locker.Unlock()
74 >
75 > c.lowWait += 1
76 > defer func() { c.lowWait -= 1 }()
77
78 > for c.lockState != PriorityMutexStateUnlocked && ctx.Err() == nil { priority_mutex_impl.go
79 c.lowCV.Wait(ctx.Done())
80 }
81
82 > if ctx.Err() != nil { priority_mutex_impl.go
83 > return ctx.Err() priority_mutex_impl.go
84 > }
85
86 c.lockState = PriorityMutexStateLockedByLow
138 }
139
140 > func (c *PriorityMutexImpl) IsLocked() bool { priority_mutex_impl.go
141 > c.locker.Lock()
142 > defer c.locker.Unlock()
143 >
144 > return c.lockState != PriorityMutexStateUnlocked
145 > }
146
147 func (c *PriorityMutexImpl) notify() {
go.temporal.io/server/common/locks/condition_variable_impl.go 11 covered LOC · 2 ranges

Open complete file

18 func NewConditionVariable(
19 lock Locker,
20 > ) *ConditionVariableImpl { condition_variable_impl.go
21 > return &ConditionVariableImpl{
22 > lock: lock,
23 >
24 > chanLock: sync.Mutex{},
25 > channel: newCVChannel(),
26 > }
27 > }
28
29 // Signal wakes one goroutine waiting on this condition variable, if there is any.