Skip to content

Commit a3a041d

Browse files
[-] fix panic for double unlock for unexpected method calls (#216)
* avoid panic for double unlock * refactor `findExpectationFunc` --------- Signed-off-by: Steve Coffman <[email protected]> Co-authored-by: Pavlo Golub <[email protected]>
1 parent 7792656 commit a3a041d

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

pgxmock.go

+4-7
Original file line numberDiff line numberDiff line change
@@ -554,25 +554,22 @@ func findExpectationFunc[ET expectationType[t], t any](c *pgxmock, method string
554554
fulfilled++
555555
continue
556556
}
557-
558557
if expected, ok = next.(ET); ok {
559-
err = cmp(expected)
560-
if err == nil {
558+
if err = cmp(expected); err == nil {
561559
break
562560
}
563561
}
562+
expected = nil
563+
next.Unlock()
564564
if c.ordered {
565-
if (!ok || err != nil) && !next.required() {
566-
next.Unlock()
565+
if !next.required() {
567566
continue
568567
}
569-
next.Unlock()
570568
if err != nil {
571569
return nil, err
572570
}
573571
return nil, fmt.Errorf("call to method %s, was not expected, next expectation is: %s", method, next)
574572
}
575-
next.Unlock()
576573
}
577574

578575
if expected == nil {

0 commit comments

Comments
 (0)