public void ShouldTimeout() { using (var store = GetDocumentStore()) { new Users_ByName().Execute(store); store.Admin.Send(new StopIndexingOperation()); using (var session = store.OpenSession()) { session.Store(new User { Name = "John" }); session.SaveChanges(); } var requestExecuter = store.GetRequestExecutor(); using (requestExecuter.ContextPool.AllocateOperationContext(out JsonOperationContext context)) { var command = new TestQueryCommand(store.Conventions, new IndexQuery { Query = $"FROM INDEX '{new Users_ByName().IndexName}'", WaitForNonStaleResultsTimeout = TimeSpan.FromMilliseconds(100), WaitForNonStaleResults = true }); var sw = Stopwatch.StartNew(); Assert.Throws <AllTopologyNodesDownException>(() => requestExecuter.Execute(command, context)); sw.Stop(); // Assert.True(sw.Elapsed < TimeSpan.FromSeconds(1), sw.Elapsed.ToString()); this can take longer when running tests in parallel but is not needed to assert if the request was cancelled or not } } }
public void ShouldTimeout() { using (var store = GetDocumentStore()) { new Users_ByName().Execute(store); store.Maintenance.Send(new StopIndexingOperation()); using (var session = store.OpenSession()) { session.Store(new User { Name = "John" }); session.SaveChanges(); } var requestExecuter = store.GetRequestExecutor(); using (var session = store.OpenAsyncSession()) using (requestExecuter.ContextPool.AllocateOperationContext(out JsonOperationContext context)) { // here we are testing that the command times out at the _network_ level. // we give much shorter timeout to the client than the server and expect to get // a good error from this var command = new TestQueryCommand((InMemoryDocumentSessionOperations)session, store.Conventions, new IndexQuery { Query = $"FROM INDEX '{new Users_ByName().IndexName}'", WaitForNonStaleResultsTimeout = TimeSpan.FromSeconds(5), WaitForNonStaleResults = true }); var sw = Stopwatch.StartNew(); var a = Assert.Throws <RavenException>(() => requestExecuter.Execute(command, context)); sw.Stop(); // Assert.True(sw.Elapsed < TimeSpan.FromSeconds(1), sw.Elapsed.ToString()); this can take longer when running tests in parallel but is not needed to assert if the request was cancelled or not } } }