wilfred-s commented on code in PR #877:
URL: https://github.com/apache/yunikorn-core/pull/877#discussion_r1619672632
##########
pkg/locking/locking_race_test.go:
##########
@@ -43,3 +44,46 @@ func TestDeadlockDetection(t *testing.T) {
mutex.Unlock() // will unwind first lock
assert.Assert(t, IsDeadlockDetected(), "Deadlock should have been
detected")
}
+
+// TestLockOrderDetection
+// lock order detection looks at the ordering of the same mutexes in different
go routines
+// if the order changes for two different go routines then that could be a
potential deadlock
+// this case happens in preemption when looking for victims when queues hover
around guaranteed
+func TestLockOrderDetection(t *testing.T) {
+ var tests = []struct {
+ name string
+ disable bool
+ }{
+ {"ordered", false},
+ {"no order", true},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ enableTrackingWithOrder(tt.disable)
+ deadlockDetected.Store(false)
+ defer disableTracking()
+
+ var wg sync.WaitGroup
+ wg.Add(1)
+ var a, b RWMutex
+ go func() { // lock ordering: a, b, b, a
+ defer wg.Done()
+ a.Lock()
+ b.RLock()
+ b.RUnlock()
+ a.Unlock()
+ }()
+ wg.Wait()
+ wg.Add(1)
+ go func() { // lock ordering: b, a, a, b
+ defer wg.Done()
+ b.Lock()
+ a.RLock()
+ a.RUnlock()
+ b.Unlock()
+ }()
Review Comment:
done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]