Ejemplo n.º 1
0
        // check that premature wait finishes on time but does not throw with false and later wait throws.
        public void ErrorHandlingTimedMethodWithError()
        {
            var         grainFullName = typeof(ErrorGrain).FullName;
            IErrorGrain grain         = GrainClient.GrainFactory.GetGrain <IErrorGrain>(GetRandomGrainId(), grainFullName);

            Task promise = grain.LongMethodWithError(2000);

            // there is a race in the test here. If run in debugger, the invocation can actually finish OK
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            Assert.False(promise.Wait(1000), "The task shouldn't have completed yet.");

            stopwatch.Stop();
            Assert.True(stopwatch.ElapsedMilliseconds >= 900, "Waited less than 900ms"); // check that we waited at least 0.9 second
            Assert.True(stopwatch.ElapsedMilliseconds <= 1100, "Waited longer than 1100ms");

            try
            {
                promise.Wait();
                Assert.True(false, "Should have thrown");
            }
            catch (Exception)
            {
            }

            Assert.True(promise.Status == TaskStatus.Faulted);
        }
Ejemplo n.º 2
0
        // check that premature wait finishes on time but does not throw with false and later wait throws.
        public void ErrorHandlingTimedMethodWithError()
        {
            var         grainFullName = typeof(ErrorGrain).FullName;
            IErrorGrain grain         = this.GrainFactory.GetGrain <IErrorGrain>(GetRandomGrainId(), grainFullName);

            Task promise = grain.LongMethodWithError(2000);

            // there is a race in the test here. If run in debugger, the invocation can actually finish OK
            Stopwatch stopwatch = Stopwatch.StartNew();

            Assert.False(promise.Wait(1000), "The task shouldn't have completed yet.");

            stopwatch.Stop();
            Assert.True(stopwatch.ElapsedMilliseconds >= 900, $"Waited less than 900ms: ({stopwatch.ElapsedMilliseconds}ms)"); // check that we waited at least 0.9 second
            Assert.True(stopwatch.ElapsedMilliseconds <= 1300, $"Waited longer than 1300ms: ({stopwatch.ElapsedMilliseconds}ms)");

            Assert.ThrowsAsync <Exception>(() => promise).Wait();

            Assert.True(promise.Status == TaskStatus.Faulted);
        }