public async Task EnsureNoDeadLockAsyncShouldStop2() { var library = new Mock <IScriptLibrary>(); using var context = new LockState(new Key("", "", TimeSpan.FromSeconds(1)), "id3", CancellationToken.None); using var protector = new LockProtector(library.Object, context, false); context.SetDone(new Exception("")); await protector.EnsureNoDeadLockAsync(); Assert.True(true); }
public void HandlerTests(string message, object initialState) { using var context = new LockState(new Key("", "", TimeSpan.FromSeconds(1)), "key", CancellationToken.None); switch (initialState) { case State.WithKey: context.SetWithKey(); break; case State.Done: context.SetDone(); break; } context.Handler(new StackExchange.Redis.RedisChannel(), message); switch (initialState) { case State.WaitingForKey: if (context.Identifier == message) { Assert.Equal(State.WithKey, context.State); } break; case State.WithKey: if (context.Identifier == message) { Assert.Equal(State.WithKey, context.State); } else { Assert.Equal(State.Done, context.State); } break; case State.Done: Assert.Equal(State.Done, context.State); break; } }
public async Task CheckSituationIsCorrectlyInterpreted(int value, object state) { var library = new Mock <IScriptLibrary>(); using var context = new LockState(new Key("", "", TimeSpan.FromMilliseconds(100)), "id4", CancellationToken.None); switch (state) { case State.WithKey: context.SetWithKey(); break; case State.Done: context.SetDone(); break; } using var protector = new LockProtector(library.Object, context, false); library.Setup(l => l.GetLockOrAddToQueue(It.IsAny <LockLuaParameters>())).ReturnsAsync(() => true); library.Setup(l => l.GetKeySituation(It.IsAny <LockLuaParameters>())).ReturnsAsync(() => value); await protector.EnsureNoDeadLockAsync(); switch (value) { case 2: switch (context.State) { case State.WaitingForKey: Assert.Equal(State.WithKey, context.State); break; case State.WithKey: case State.Done: Assert.Equal(State.Done, context.State); break; } break; } }