public void Throws_operation_canceled_after_timeout() { CancellationToken cancellationToken = new CancellationTokenSource(TimeSpan.FromMilliseconds(300)).Token; (var block, var transaction) = PrepareTx(BlockNumber, 100000, new byte[] { 0, 0, 0 }); ParityLikeTxTracer tracer = new ParityLikeTxTracer(block, transaction, ParityTraceTypes.Trace, cancellationToken); try { tracer.StartOperation(0, 0, Instruction.ADD, 0); } catch (Exception ex) { if (ex is OperationCanceledException) { Assert.Fail("Threw OperationCancelledException before timeout."); } } Thread.Sleep(TimeSpan.FromMilliseconds(500)); Assert.Throws <OperationCanceledException>(() => tracer.StartOperation(0, 0, Instruction.ADD, 0)); }
public void Throw_operation_canceled_after_given_timeout() { var timeout = TimeSpan.FromMilliseconds(100); Transaction transactionMock = Substitute.For <Transaction>(); ParityTraceTypes type = ParityTraceTypes.Trace; Address address = new Address(new byte[] { 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1 }); CancellationToken cancellationToken = new CancellationTokenSource(timeout).Token; ParityLikeTxTracer tracer = new ParityLikeTxTracer(_blockTree.Head, transactionMock, type, cancellationToken); Thread.Sleep(timeout.Add(TimeSpan.FromMilliseconds(100))); Assert.Throws <OperationCanceledException>(() => tracer.StartOperation(0, 0, default(Instruction), 0)); Assert.Throws <OperationCanceledException>(() => tracer.ReportAction(0, 0, address, address, new byte[] { 0, 0, 0 }, ExecutionType.Transaction)); Assert.Throws <OperationCanceledException>(() => tracer.ReportAction(0, 0, address, address, new byte[] { 0, 0, 0 }, ExecutionType.Transaction)); Assert.Throws <OperationCanceledException>(() => tracer.ReportSelfDestruct(address, 0, address)); Assert.Throws <OperationCanceledException>(() => tracer.ReportStackPush(null)); }