File tree Expand file tree Collapse file tree 3 files changed +34
-19
lines changed Expand file tree Collapse file tree 3 files changed +34
-19
lines changed Original file line number Diff line number Diff line change 1
1
using System ;
2
+ using System . Diagnostics ;
3
+ using System . Threading ;
2
4
3
5
namespace NGitLab . Mock . Clients ;
4
6
5
- internal sealed class ClientContext
7
+ internal sealed class ClientContext ( GitLabServer server , User user )
6
8
{
7
- public ClientContext ( GitLabServer server , User user )
8
- {
9
- Server = server ;
10
- User = user ;
11
- }
9
+ private readonly SemaphoreSlim _operationLock = new ( 1 , 1 ) ;
12
10
13
- public GitLabServer Server { get ; }
11
+ public GitLabServer Server { get ; } = server ;
14
12
15
- public User User { get ; }
13
+ public User User { get ; } = user ;
16
14
17
15
public bool IsAuthenticated => User != null ;
18
16
19
17
public IDisposable BeginOperationScope ( )
20
18
{
21
19
Server . RaiseOnClientOperation ( ) ;
22
- return new Releaser ( ) ;
20
+ return new Releaser ( _operationLock ) ;
23
21
}
24
22
25
23
private sealed class Releaser : IDisposable
26
24
{
27
- public Releaser ( )
25
+ private readonly SemaphoreSlim _operationLock ;
26
+
27
+ public Releaser ( SemaphoreSlim operationLock )
28
28
{
29
+ _operationLock = operationLock ;
30
+ if ( Debugger . IsAttached && _operationLock . CurrentCount == 0 )
31
+ Debugger . Break ( ) ;
32
+ _operationLock . Wait ( ) ;
29
33
}
30
34
31
35
public void Dispose ( )
32
36
{
37
+ _operationLock . Release ( ) ;
33
38
}
34
39
}
35
40
}
Original file line number Diff line number Diff line change @@ -156,13 +156,18 @@ public Models.Group GetGroup(GroupId id)
156
156
{
157
157
using ( Context . BeginOperationScope ( ) )
158
158
{
159
- var group = Server . AllGroups . FirstOrDefault ( g => id . Equals ( g . PathWithNameSpace , g . Id ) ) ;
159
+ return GetGroupLockless ( id ) ;
160
+ }
161
+ }
160
162
161
- if ( group == null || ! group . CanUserViewGroup ( Context . User ) )
162
- throw GitLabException . NotFound ( ) ;
163
+ private Models . Group GetGroupLockless ( GroupId id )
164
+ {
165
+ var group = Server . AllGroups . FirstOrDefault ( g => id . Equals ( g . PathWithNameSpace , g . Id ) ) ;
163
166
164
- return group . ToClientGroup ( Context . User ) ;
165
- }
167
+ if ( group == null || ! group . CanUserViewGroup ( Context . User ) )
168
+ throw GitLabException . NotFound ( ) ;
169
+
170
+ return group . ToClientGroup ( Context . User ) ;
166
171
}
167
172
168
173
public Task < Models . Group > GetByFullPathAsync ( string fullPath , CancellationToken cancellationToken = default ) => GetGroupAsync ( fullPath , cancellationToken ) ;
@@ -333,7 +338,7 @@ public Models.Group Update(long id, GroupUpdate groupUpdate)
333
338
{
334
339
using ( Context . BeginOperationScope ( ) )
335
340
{
336
- var parentGroup = GetGroup ( groupId ) ;
341
+ var parentGroup = GetGroupLockless ( groupId ) ;
337
342
var groups = Server . AllGroups . Where ( group => group . CanUserViewGroup ( Context . User ) ) ;
338
343
339
344
if ( query is not null )
Original file line number Diff line number Diff line change @@ -20,19 +20,24 @@ public IEnumerable<Models.GroupHook> All
20
20
{
21
21
using ( Context . BeginOperationScope ( ) )
22
22
{
23
- var hooks = GetGroup ( _groupId , GroupPermission . Edit ) . Hooks ;
24
- return ToClientGroupHooks ( hooks ) . ToList ( ) ;
23
+ return GetAllLockless ( ) ;
25
24
}
26
25
}
27
26
}
28
27
28
+ private List < Models . GroupHook > GetAllLockless ( )
29
+ {
30
+ var hooks = GetGroup ( _groupId , GroupPermission . Edit ) . Hooks ;
31
+ return ToClientGroupHooks ( hooks ) . ToList ( ) ;
32
+ }
33
+
29
34
public Models . GroupHook this [ long hookId ]
30
35
{
31
36
get
32
37
{
33
38
using ( Context . BeginOperationScope ( ) )
34
39
{
35
- var hook = All . FirstOrDefault ( h => h . Id == hookId ) ?? throw GitLabException . NotFound ( ) ;
40
+ var hook = GetAllLockless ( ) . FirstOrDefault ( h => h . Id == hookId ) ?? throw GitLabException . NotFound ( ) ;
36
41
return hook ;
37
42
}
38
43
}
You can’t perform that action at this time.
0 commit comments