Esempio n. 1
0
        public void AsyncJobMultipleFinishedOnPredicate()
        {
            SteamClient client = new SteamClient();

            AsyncJobMultiple <Callback> asyncJob = new AsyncJobMultiple <Callback>(client, 123, call => call.IsFinished);
            Task <AsyncJobMultiple <Callback> .ResultSet> asyncTask = asyncJob.ToTask();

            bool jobFinished = asyncJob.AddResult(new Callback {
                JobID = 123, IsFinished = false
            });

            Assert.False(jobFinished, "Async job should not inform that it is finished when completion predicate is false after a result is given");
            Assert.False(asyncTask.IsCompleted, "Async job should not be completed when completion predicate is false");
            Assert.False(asyncTask.IsCanceled, "Async job should not be canceled when completion predicate is false");
            Assert.False(asyncTask.IsFaulted, "Async job should not be faulted when completion predicate is false");

            jobFinished = asyncJob.AddResult(new Callback {
                JobID = 123, IsFinished = true
            });

            Assert.True(jobFinished, "Async job should inform completion when completion predicat is passed after a result is given");
            Assert.True(asyncTask.IsCompleted, "Async job should be completed when completion predicate is true");
            Assert.False(asyncTask.IsCanceled, "Async job should not be canceled when completion predicate is true");
            Assert.False(asyncTask.IsFaulted, "Async job should not be faulted when completion predicate is true");
        }
Esempio n. 2
0
        public void AsyncJobMultipleCompletesOnIncompleteResultAndFailure()
        {
            SteamClient client = new SteamClient();

            client.jobManager.SetTimeoutsEnabled(true);

            AsyncJobMultiple <Callback> asyncJob = new AsyncJobMultiple <Callback>(client, 123, call => call.IsFinished);

            asyncJob.Timeout = TimeSpan.FromSeconds(1);

            Task <AsyncJobMultiple <Callback> .ResultSet> asyncTask = asyncJob.ToTask();

            Callback onlyResult = new Callback {
                JobID = 123, IsFinished = false
            };

            asyncJob.AddResult(onlyResult);

            asyncJob.SetFailed(dueToRemoteFailure: true);

            Assert.True(asyncTask.IsCompleted, "AsyncJobMultiple should be completed on partial (failed) result set");
            Assert.False(asyncTask.IsCanceled, "AsyncJobMultiple should not be canceled on partial (failed) result set");
            Assert.False(asyncTask.IsFaulted, "AsyncJobMultiple should not be faulted on a partial (failed) result set");

            AsyncJobMultiple <Callback> .ResultSet result = asyncTask.Result;

            Assert.False(result.Complete, "ResultSet should be incomplete");
            Assert.True(result.Failed, "ResultSet should be failed");
            Assert.Equal(result.Results.Count, 1);
            Assert.Contains(onlyResult, result.Results);
        }
Esempio n. 3
0
        public async Task AsyncJobMultipleCompletesOnIncompleteResult()
        {
            SteamClient client = new SteamClient();

            client.jobManager.SetTimeoutsEnabled(true);

            AsyncJobMultiple <Callback> asyncJob = new AsyncJobMultiple <Callback>(client, 123, call => call.IsFinished);

            asyncJob.Timeout = TimeSpan.FromSeconds(1);

            Task <AsyncJobMultiple <Callback> .ResultSet> asyncTask = asyncJob.ToTask();

            Callback onlyResult = new Callback {
                JobID = 123, IsFinished = false
            };

            asyncJob.AddResult(onlyResult);

            // adding a result will extend the job's timeout, but we'll cheat here and decrease it
            asyncJob.Timeout = TimeSpan.FromSeconds(1);

            await Task.Delay(TimeSpan.FromSeconds(5));

            Assert.True(asyncTask.IsCompleted, "AsyncJobMultiple should be completed on partial (timed out) result set");
            Assert.False(asyncTask.IsCanceled, "AsyncJobMultiple should not be canceled on partial (timed out) result set");
            Assert.False(asyncTask.IsFaulted, "AsyncJobMultiple should not be faulted on a partial (failed) result set");

            AsyncJobMultiple <Callback> .ResultSet result = asyncTask.Result;

            Assert.False(result.Complete, "ResultSet should be incomplete");
            Assert.False(result.Failed, "ResultSet should not be failed");
            Assert.Equal(result.Results.Count, 1);
            Assert.Contains(onlyResult, result.Results);
        }
Esempio n. 4
0
        public void AsyncJobMultipleThrowsExceptionOnNullCallback()
        {
            SteamClient client = new SteamClient();

            AsyncJobMultiple <Callback> asyncJob = new AsyncJobMultiple <Callback>(client, 123, call => true);

            Assert.Throws <ArgumentNullException>(() => asyncJob.AddResult(null));
        }
Esempio n. 5
0
        public async Task AsyncJobMultipleExtendsTimeoutOnMessage()
        {
            SteamClient client = new SteamClient();

            client.jobManager.SetTimeoutsEnabled(true);

            AsyncJobMultiple <Callback> asyncJob = new AsyncJobMultiple <Callback>(client, 123, call => call.IsFinished);

            asyncJob.Timeout = TimeSpan.FromSeconds(5);

            Task <AsyncJobMultiple <Callback> .ResultSet> asyncTask = asyncJob.ToTask();

            // wait 3 seconds before we post any results to this job at all
            await Task.Delay(TimeSpan.FromSeconds(3));

            // we should not be completed or canceled yet
            Assert.False(asyncTask.IsCompleted, "AsyncJobMultiple should not be completed after 3 seconds of 5 second timeout");
            Assert.False(asyncTask.IsCanceled, "AsyncJobMultiple should not be canceled after 3 seconds of 5 second timeout");
            Assert.False(asyncTask.IsFaulted, "AsyncJobMultiple should not be faulted after 3 econds of 5 second timeout");

            // give result 1 of 2
            asyncJob.AddResult(new Callback {
                JobID = 123, IsFinished = false
            });

            // delay for what the original timeout would have been
            await Task.Delay(TimeSpan.FromSeconds(5));

            // we still shouldn't be completed or canceled (timed out)
            Assert.False(asyncTask.IsCompleted, "AsyncJobMultiple should not be completed 5 seconds after a result was added (result should extend timeout)");
            Assert.False(asyncTask.IsCanceled, "AsyncJobMultiple should not be canceled 5 seconds after a result was added (result should extend timeout)");
            Assert.False(asyncTask.IsFaulted, "AsyncJobMultiple should not be faulted 5 seconds aftr a result was added (result should extend timeout)");

            asyncJob.AddResult(new Callback {
                JobID = 123, IsFinished = true
            });

            // we should be completed but not canceled or faulted
            Assert.True(asyncTask.IsCompleted, "AsyncJobMultiple should be completed when final result is added to set");
            Assert.False(asyncTask.IsCanceled, "AsyncJobMultiple should not be canceled when final result is added to set");
            Assert.False(asyncTask.IsFaulted, "AsyncJobMultiple should not be faulted when final result is added to set");
        }
Esempio n. 6
0
        public void AsyncJobMultipleFinishedOnEmptyPredicate()
        {
            SteamClient client = new SteamClient();

            AsyncJobMultiple <Callback> asyncJob = new AsyncJobMultiple <Callback>(client, 123, call => true);
            Task <AsyncJobMultiple <Callback> .ResultSet> asyncTask = asyncJob.ToTask();

            bool jobFinished = asyncJob.AddResult(new Callback {
                JobID = 123
            });

            Assert.True(jobFinished, "Async job should inform that it is completed when completion predicate is always true and a result is given");
            Assert.True(asyncTask.IsCompleted, "Async job should be completed when empty predicate result is given");
            Assert.False(asyncTask.IsCanceled, "Async job should not be canceled when empty predicate result is given");
            Assert.False(asyncTask.IsFaulted, "Async job should not be faulted when empty predicate result is given");
        }
Esempio n. 7
0
        public async Task AsyncJobMultipleContinuesAsynchronously()
        {
            SteamClient client = new SteamClient();

            var asyncJob  = new AsyncJobMultiple <Callback>(client, 123, call => true);
            var asyncTask = asyncJob.ToTask();

            var continuationThreadID = -1;
            var continuation         = asyncTask.ContinueWith(t =>
            {
                continuationThreadID = Thread.CurrentThread.ManagedThreadId;
            }, TaskContinuationOptions.ExecuteSynchronously);

            var completionThreadID = Thread.CurrentThread.ManagedThreadId;

            asyncJob.AddResult(new Callback {
                JobID = 123
            });

            await continuation;

            Assert.NotEqual(-1, continuationThreadID);
            Assert.NotEqual(completionThreadID, continuationThreadID);
        }
Esempio n. 8
0
        public void AsyncJobMultipleContinuesAsynchronously()
        {
            SteamClient client = new SteamClient();

            var asyncJob  = new AsyncJobMultiple <Callback>(client, 123, call => true);
            var asyncTask = asyncJob.ToTask();

            var continuationThreadID = -1;
            var continuation         = asyncTask.ContinueWith(t =>
            {
                continuationThreadID = Environment.CurrentManagedThreadId;
            }, TaskContinuationOptions.ExecuteSynchronously);

            var completionThreadID = Environment.CurrentManagedThreadId;

            asyncJob.AddResult(new Callback {
                JobID = 123
            });

            WaitForTaskWithoutRunningInline(continuation);

            Assert.NotEqual(-1, continuationThreadID);
            Assert.NotEqual(completionThreadID, continuationThreadID);
        }
Esempio n. 9
0
        public void AsyncJobMultipleThrowsExceptionOnNullCallback()
        {
            SteamClient client = new SteamClient();

            AsyncJobMultiple<Callback> asyncJob = new AsyncJobMultiple<Callback>( client, 123, call => true );

            Assert.Throws<ArgumentNullException>( () => asyncJob.AddResult( null ) );
        }
Esempio n. 10
0
        public void AsyncJobMultipleCompletesOnIncompleteResultAndFailure()
        {
            SteamClient client = new SteamClient();
            client.jobManager.SetTimeoutsEnabled( true );

            AsyncJobMultiple<Callback> asyncJob = new AsyncJobMultiple<Callback>( client, 123, call => call.IsFinished );
            asyncJob.Timeout = TimeSpan.FromSeconds( 1 );

            Task<AsyncJobMultiple<Callback>.ResultSet> asyncTask = asyncJob.ToTask();

            Callback onlyResult = new Callback { JobID = 123, IsFinished = false };

            asyncJob.AddResult( onlyResult );

            asyncJob.SetFailed( dueToRemoteFailure: true );

            Assert.True( asyncTask.IsCompleted, "AsyncJobMultiple should be completed on partial (failed) result set" );
            Assert.False( asyncTask.IsCanceled, "AsyncJobMultiple should not be canceled on partial (failed) result set" );
            Assert.False( asyncTask.IsFaulted, "AsyncJobMultiple should not be faulted on a partial (failed) result set" );

            AsyncJobMultiple<Callback>.ResultSet result = asyncTask.Result;

            Assert.False( result.Complete, "ResultSet should be incomplete" );
            Assert.True( result.Failed, "ResultSet should be failed" );
            Assert.Equal( result.Results.Count, 1 );
            Assert.Contains( onlyResult, result.Results );
        }
Esempio n. 11
0
        public async void AsyncJobMultipleCompletesOnIncompleteResult()
        {
            SteamClient client = new SteamClient();
            client.jobManager.SetTimeoutsEnabled( true );

            AsyncJobMultiple<Callback> asyncJob = new AsyncJobMultiple<Callback>( client, 123, call => call.IsFinished );
            asyncJob.Timeout = TimeSpan.FromSeconds( 1 );

            Task<AsyncJobMultiple<Callback>.ResultSet> asyncTask = asyncJob.ToTask();

            Callback onlyResult = new Callback { JobID = 123, IsFinished = false };

            asyncJob.AddResult( onlyResult );

            // adding a result will extend the job's timeout, but we'll cheat here and decrease it
            asyncJob.Timeout = TimeSpan.FromSeconds( 1 );

            await Task.Delay( TimeSpan.FromSeconds( 5 ) );

            Assert.True( asyncTask.IsCompleted, "AsyncJobMultiple should be completed on partial (timed out) result set" );
            Assert.False( asyncTask.IsCanceled, "AsyncJobMultiple should not be canceled on partial (timed out) result set" );
            Assert.False( asyncTask.IsFaulted, "AsyncJobMultiple should not be faulted on a partial (failed) result set" );

            AsyncJobMultiple<Callback>.ResultSet result = asyncTask.Result;

            Assert.False( result.Complete, "ResultSet should be incomplete" );
            Assert.False( result.Failed, "ResultSet should not be failed" );
            Assert.Equal( result.Results.Count, 1 );
            Assert.Contains( onlyResult, result.Results );
        }
Esempio n. 12
0
        public async void AsyncJobMultipleExtendsTimeoutOnMessage()
        {
            SteamClient client = new SteamClient();
            client.jobManager.SetTimeoutsEnabled( true );

            AsyncJobMultiple<Callback> asyncJob = new AsyncJobMultiple<Callback>( client, 123, call => call.IsFinished );
            asyncJob.Timeout = TimeSpan.FromSeconds( 5 );

            Task<AsyncJobMultiple<Callback>.ResultSet> asyncTask = asyncJob.ToTask();

            // wait 3 seconds before we post any results to this job at all
            await Task.Delay( TimeSpan.FromSeconds( 3 ) );

            // we should not be completed or canceled yet
            Assert.False( asyncTask.IsCompleted, "AsyncJobMultiple should not be completed after 3 seconds of 5 second timeout" );
            Assert.False( asyncTask.IsCanceled, "AsyncJobMultiple should not be canceled after 3 seconds of 5 second timeout" );
            Assert.False( asyncTask.IsFaulted, "AsyncJobMultiple should not be faulted after 3 econds of 5 second timeout" );

            // give result 1 of 2
            asyncJob.AddResult( new Callback { JobID = 123, IsFinished = false } );

            // delay for what the original timeout would have been
            await Task.Delay( TimeSpan.FromSeconds( 5 ) );

            // we still shouldn't be completed or canceled (timed out)
            Assert.False( asyncTask.IsCompleted, "AsyncJobMultiple should not be completed 5 seconds after a result was added (result should extend timeout)" );
            Assert.False( asyncTask.IsCanceled, "AsyncJobMultiple should not be canceled 5 seconds after a result was added (result should extend timeout)" );
            Assert.False( asyncTask.IsFaulted, "AsyncJobMultiple should not be faulted 5 seconds aftr a result was added (result should extend timeout)" );

            asyncJob.AddResult( new Callback { JobID = 123, IsFinished = true } );

            // we should be completed but not canceled or faulted
            Assert.True( asyncTask.IsCompleted, "AsyncJobMultiple should be completed when final result is added to set" );
            Assert.False( asyncTask.IsCanceled, "AsyncJobMultiple should not be canceled when final result is added to set" );
            Assert.False( asyncTask.IsFaulted, "AsyncJobMultiple should not be faulted when final result is added to set" );
        }
Esempio n. 13
0
        public void AsyncJobMultipleFinishedOnPredicate()
        {
            SteamClient client = new SteamClient();

            AsyncJobMultiple<Callback> asyncJob = new AsyncJobMultiple<Callback>( client, 123, call => call.IsFinished );
            Task<AsyncJobMultiple<Callback>.ResultSet> asyncTask = asyncJob.ToTask();

            bool jobFinished = asyncJob.AddResult( new Callback { JobID = 123, IsFinished = false } );

            Assert.False( jobFinished, "Async job should not inform that it is finished when completion predicate is false after a result is given" );
            Assert.False( asyncTask.IsCompleted, "Async job should not be completed when completion predicate is false" );
            Assert.False( asyncTask.IsCanceled, "Async job should not be canceled when completion predicate is false" );
            Assert.False( asyncTask.IsFaulted, "Async job should not be faulted when completion predicate is false" );

            jobFinished = asyncJob.AddResult( new Callback { JobID = 123, IsFinished = true } );

            Assert.True( jobFinished, "Async job should inform completion when completion predicat is passed after a result is given" );
            Assert.True( asyncTask.IsCompleted, "Async job should be completed when completion predicate is true" );
            Assert.False( asyncTask.IsCanceled, "Async job should not be canceled when completion predicate is true" );
            Assert.False( asyncTask.IsFaulted, "Async job should not be faulted when completion predicate is true" );
        }
Esempio n. 14
0
        public void AsyncJobMultipleFinishedOnEmptyPredicate()
        {
            SteamClient client = new SteamClient();

            AsyncJobMultiple<Callback> asyncJob = new AsyncJobMultiple<Callback>( client, 123, call => true );
            Task<AsyncJobMultiple<Callback>.ResultSet> asyncTask = asyncJob.ToTask();

            bool jobFinished = asyncJob.AddResult( new Callback { JobID = 123 } );

            Assert.True( jobFinished, "Async job should inform that it is completed when completion predicate is always true and a result is given" );
            Assert.True( asyncTask.IsCompleted, "Async job should be completed when empty predicate result is given" );
            Assert.False( asyncTask.IsCanceled, "Async job should not be canceled when empty predicate result is given" );
            Assert.False( asyncTask.IsFaulted, "Async job should not be faulted when empty predicate result is given" );
        }