public async Task SendingMoveRequestToServerThatSendsPendingResponsesTooSlowlyShouldTimeout() { var port = Ports.GetNext(); using (CreateServer <SlowPendingResponsesDicomServer>(port)) { var client = CreateClient(port); client.ServiceOptions.RequestTimeout = TimeSpan.FromSeconds(2); var request = new DicomCMoveRequest("another-AE", "study123"); DicomRequest.OnTimeoutEventArgs onTimeoutEventArgs = null; request.OnTimeout += (sender, args) => onTimeoutEventArgs = args; RequestTimedOutEventArgs eventArgsFromDicomClientRequestTimedOut = null; client.RequestTimedOut += (sender, args) => eventArgsFromDicomClientRequestTimedOut = args; await client.AddRequestAsync(request).ConfigureAwait(false); var sendTask = client.SendAsync(); var sendTimeoutCancellationTokenSource = new CancellationTokenSource(); var sendTimeout = Task.Delay(TimeSpan.FromSeconds(10), sendTimeoutCancellationTokenSource.Token); var winner = await Task.WhenAny(sendTask, sendTimeout).ConfigureAwait(false); sendTimeoutCancellationTokenSource.Cancel(); sendTimeoutCancellationTokenSource.Dispose(); Assert.Equal(winner, sendTask); Assert.NotNull(onTimeoutEventArgs); Assert.NotNull(eventArgsFromDicomClientRequestTimedOut); Assert.Equal(request, eventArgsFromDicomClientRequestTimedOut.Request); Assert.Equal(client.ServiceOptions.RequestTimeout, eventArgsFromDicomClientRequestTimedOut.Timeout); } }
public async Task SendingLargeFileUsingVeryShortResponseTimeoutAndSendingTakesTooLongShouldFail() { var port = Ports.GetNext(); using (CreateServer <InMemoryDicomCStoreProvider>(port)) { var client = CreateClient(port); client.Options.RequestTimeout = TimeSpan.FromSeconds(1); client.Options.MaxPDULength = 16 * 1024; TimeSpan streamWriteTimeout = TimeSpan.FromMilliseconds(1500); client.NetworkManager = new ConfigurableNetworkManager(() => Thread.Sleep(streamWriteTimeout)); DicomResponse response = null; DicomRequest.OnTimeoutEventArgs onTimeoutEventArgs = null; // Size = 5 192 KB, one PDU = 16 KB, so this will result in 325 PDUs // If stream timeout = 1500ms, then total time to send will be 325 * 1500 = 487.5 seconds var request = new DicomCStoreRequest(@"./Test Data/10200904.dcm") { OnResponseReceived = (req, res) => response = res, OnTimeout = (sender, args) => onTimeoutEventArgs = args }; RequestTimedOutEventArgs eventArgsFromDicomClientRequestTimedOut = null; client.RequestTimedOut += (sender, args) => eventArgsFromDicomClientRequestTimedOut = args; await client.AddRequestAsync(request).ConfigureAwait(false); var sendTask = client.SendAsync(); var sendTimeoutCancellationTokenSource = new CancellationTokenSource(); var sendTimeout = Task.Delay(TimeSpan.FromSeconds(10), sendTimeoutCancellationTokenSource.Token); var winner = await Task.WhenAny(sendTask, sendTimeout).ConfigureAwait(false); sendTimeoutCancellationTokenSource.Cancel(); sendTimeoutCancellationTokenSource.Dispose(); Assert.Same(winner, sendTask); Assert.Null(response); Assert.NotNull(onTimeoutEventArgs); Assert.NotNull(eventArgsFromDicomClientRequestTimedOut); Assert.Equal(request, eventArgsFromDicomClientRequestTimedOut.Request); Assert.Equal(client.Options.RequestTimeout, eventArgsFromDicomClientRequestTimedOut.Timeout); } }
public async Task SendingFindRequestToServerThatNeverRespondsShouldTimeout() { var port = Ports.GetNext(); using (CreateServer <NeverRespondingDicomServer>(port)) { var client = CreateClient(port); client.ServiceOptions.RequestTimeout = TimeSpan.FromSeconds(2); var request = new DicomCFindRequest(DicomQueryRetrieveLevel.Patient) { Dataset = new DicomDataset { { DicomTag.PatientID, "PAT123" } }, OnResponseReceived = (req, res) => throw new Exception("Did not expect a response"), }; DicomRequest.OnTimeoutEventArgs eventArgsFromRequestTimeout = null; request.OnTimeout += (sender, args) => eventArgsFromRequestTimeout = args; RequestTimedOutEventArgs eventArgsFromDicomClientRequestTimedOut = null; client.RequestTimedOut += (sender, args) => eventArgsFromDicomClientRequestTimedOut = args; await client.AddRequestAsync(request).ConfigureAwait(false); var sendTask = client.SendAsync(); var sendTimeoutCancellationTokenSource = new CancellationTokenSource(); var sendTimeout = Task.Delay(TimeSpan.FromSeconds(10), sendTimeoutCancellationTokenSource.Token); var winner = await Task.WhenAny(sendTask, sendTimeout).ConfigureAwait(false); sendTimeoutCancellationTokenSource.Cancel(); sendTimeoutCancellationTokenSource.Dispose(); Assert.Equal(winner, sendTask); Assert.NotNull(eventArgsFromRequestTimeout); Assert.NotNull(eventArgsFromDicomClientRequestTimedOut); Assert.Equal(request, eventArgsFromDicomClientRequestTimedOut.Request); Assert.Equal(client.ServiceOptions.RequestTimeout, eventArgsFromDicomClientRequestTimedOut.Timeout); } }
internal void NotifyRequestTimedOut(RequestTimedOutEventArgs eventArgs) => RequestTimedOut?.Invoke(this, eventArgs);
private void OnConnectionRequestTimedOut(object o, RequestTimedOutEventArgs e) { spState.Text = "Connection request to " + e.ServerIP + ":" + e.ServerPort.ToString() + " timed out."; btnConnect.Enabled = true; }
/// <summary> /// Connection request timed out. /// </summary> private void m_UDP_OnConnectionRequestTimedOut(object o, RequestTimedOutEventArgs e) { this.Invoke(new GenesisCore.RequestTimedOutHandler(OnConnectionRequestTimedOut), new object [] { o, e }); }