11using System ;
22using System . Diagnostics ;
3+ using System . Runtime . CompilerServices ;
34using System . Threading ;
45
56namespace NGitLab . Mock . Clients ;
@@ -14,10 +15,20 @@ internal sealed class ClientContext(GitLabServer server, User user)
1415
1516 public bool IsAuthenticated => User != null ;
1617
17- public IDisposable BeginOperationScope ( )
18+ public IDisposable BeginOperationScope (
19+ [ CallerMemberName ] string callingMethod = null ,
20+ [ CallerFilePath ] string callingFilePath = null ,
21+ [ CallerLineNumber ] int callingLineNumber = - 1 )
1822 {
1923 Server . RaiseOnClientOperation ( ) ;
20- return new Releaser ( _operationLock ) ;
24+ var releaser = new Releaser ( _operationLock ) ;
25+
26+ // Store caller info for debugging purposes
27+ Releaser . MethodWhereLockWasTaken = callingMethod ;
28+ Releaser . FilePathWhereLockWasTaken = callingFilePath ;
29+ Releaser . LineNumberWhereLockWasTaken = callingLineNumber ;
30+
31+ return releaser ;
2132 }
2233
2334 private sealed class Releaser : IDisposable
@@ -27,11 +38,18 @@ private sealed class Releaser : IDisposable
2738 public Releaser ( SemaphoreSlim operationLock )
2839 {
2940 _operationLock = operationLock ;
30- if ( Debugger . IsAttached && _operationLock . CurrentCount == 0 )
41+ if ( _operationLock . CurrentCount == 0 && Debugger . IsAttached )
3142 Debugger . Break ( ) ;
3243 _operationLock . Wait ( ) ;
3344 }
3445
46+ // The following is for debugging purposes only. It stores info about where the active lock was taken.
47+ public static string MethodWhereLockWasTaken { get ; set ; }
48+
49+ public static string FilePathWhereLockWasTaken { get ; set ; }
50+
51+ public static int LineNumberWhereLockWasTaken { get ; set ; }
52+
3553 public void Dispose ( )
3654 {
3755 _operationLock . Release ( ) ;
0 commit comments