Exemplo n.º 1
0
        public void AsyncJobCtorRegistersJob()
        {
            SteamClient client = new SteamClient();

            AsyncJob<Callback> asyncJob = new AsyncJob<Callback>( client, 123 );

            Assert.True( client.jobManager.asyncJobs.ContainsKey( asyncJob ), "Async job dictionary should contain the jobid key" );
            Assert.True( client.jobManager.asyncJobs.ContainsKey( 123 ), "Async job dictionary should contain jobid key as a value type" );
        }
Exemplo n.º 2
0
        public void AsyncJobClearsOnCompletion()
        {
            SteamClient client = new SteamClient();

            AsyncJob<Callback> asyncJob = new AsyncJob<Callback>( client, 123 );

            client.PostCallback( new Callback { JobID = 123 } );

            Assert.False( client.jobManager.asyncJobs.ContainsKey( asyncJob ), "Async job dictionary should no longer contain jobid key after callback is posted" );
            Assert.False( client.jobManager.asyncJobs.ContainsKey( 123 ), "Async job dictionary should no longer contain jobid key (as value type) after callback is posted" );
        }
Exemplo n.º 3
0
        public void AysncJobCompletesOnCallback()
        {
            SteamClient client = new SteamClient();

            AsyncJob<Callback> asyncJob = new AsyncJob<Callback>( client, 123 );
            Task<Callback> asyncTask = asyncJob.ToTask();

            client.PostCallback( new Callback { JobID = 123 } );

            Assert.True( asyncTask.IsCompleted, "Async job should be completed after callback is posted" );
            Assert.False( asyncTask.IsCanceled, "Async job should not be canceled after callback is posted" );
            Assert.False( asyncTask.IsFaulted, "Async job should not be faulted after callback is posted" );
        }
Exemplo n.º 4
0
        public async void AsyncJobClearsOnTimeout()
        {
            SteamClient client = new SteamClient();
            client.jobManager.SetTimeoutsEnabled( true );

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

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

            Assert.False( client.jobManager.asyncJobs.ContainsKey( asyncJob ), "Async job dictionary should no longer contain jobid key after timeout" );
            Assert.False( client.jobManager.asyncJobs.ContainsKey( 123 ), "Async job dictionary should no longer contain jobid key (as value type) after timeout" );
        }
Exemplo n.º 5
0
        public void AsyncJobClearsOnCompletion()
        {
            SteamClient client = new SteamClient();

            AsyncJob <Callback> asyncJob = new AsyncJob <Callback>(client, 123);

            client.PostCallback(new Callback {
                JobID = 123
            });

            Assert.False(client.jobManager.asyncJobs.ContainsKey(asyncJob), "Async job dictionary should no longer contain jobid key after callback is posted");
            Assert.False(client.jobManager.asyncJobs.ContainsKey(123), "Async job dictionary should no longer contain jobid key (as value type) after callback is posted");
        }
Exemplo n.º 6
0
        public void AsyncJobGivesBackCallback()
        {
            SteamClient client = new SteamClient();

            AsyncJob <Callback> asyncJob = new AsyncJob <Callback>(client, 123);
            Task <Callback>     jobTask  = asyncJob.ToTask();

            Callback ourCallback = new Callback {
                JobID = 123
            };

            client.PostCallback(ourCallback);

            Assert.Same(jobTask.Result, ourCallback);
        }
Exemplo n.º 7
0
        public async Task AsyncJobThrowsFailureExceptionOnFailure()
        {
            SteamClient client = new SteamClient();

            AsyncJob <Callback> asyncJob  = new AsyncJob <Callback>(client, 123);
            Task <Callback>     asyncTask = asyncJob.ToTask();

            asyncJob.SetFailed(dueToRemoteFailure: true);

            Assert.True(asyncTask.IsCompleted, "Async job should be completed after job failure");
            Assert.False(asyncTask.IsCanceled, "Async job should not be canceled after job failure");
            Assert.True(asyncTask.IsFaulted, "Async job should be faulted after job failure");

            await Assert.ThrowsAsync(typeof(AsyncJobFailedException), async() => await asyncTask);
        }
Exemplo n.º 8
0
        public async void AsyncJobCancelsOnSetFailedTimeout()
        {
            SteamClient client = new SteamClient();

            AsyncJob<Callback> asyncJob = new AsyncJob<Callback>( client, 123 );
            Task<Callback> asyncTask = asyncJob.ToTask();

            asyncJob.SetFailed( dueToRemoteFailure: false );
            
            Assert.True( asyncTask.IsCompleted, "Async job should be completed on message timeout" );
            Assert.True( asyncTask.IsCanceled, "Async job should be canceled on message timeout" );
            Assert.False( asyncTask.IsFaulted, "Async job should not be faulted on message timeout" );

            await Assert.ThrowsAsync( typeof( TaskCanceledException ), async () => await asyncTask );
        }
Exemplo n.º 9
0
        public async Task AsyncJobClearsOnTimeout()
        {
            SteamClient client = new SteamClient();

            client.jobManager.SetTimeoutsEnabled(true);

            AsyncJob <Callback> asyncJob = new AsyncJob <Callback>(client, 123);

            asyncJob.Timeout = TimeSpan.FromSeconds(1);

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

            Assert.False(client.jobManager.asyncJobs.ContainsKey(asyncJob), "Async job dictionary should no longer contain jobid key after timeout");
            Assert.False(client.jobManager.asyncJobs.ContainsKey(123), "Async job dictionary should no longer contain jobid key (as value type) after timeout");
        }
Exemplo n.º 10
0
        public void AysncJobCompletesOnCallback()
        {
            SteamClient client = new SteamClient();

            AsyncJob <Callback> asyncJob  = new AsyncJob <Callback>(client, 123);
            Task <Callback>     asyncTask = asyncJob.ToTask();

            client.PostCallback(new Callback {
                JobID = 123
            });

            Assert.True(asyncTask.IsCompleted, "Async job should be completed after callback is posted");
            Assert.False(asyncTask.IsCanceled, "Async job should not be canceled after callback is posted");
            Assert.False(asyncTask.IsFaulted, "Async job should not be faulted after callback is posted");
        }
Exemplo n.º 11
0
        public async Task AsyncJobCancelsOnSetFailedTimeout()
        {
            SteamClient client = new SteamClient();

            AsyncJob <Callback> asyncJob  = new AsyncJob <Callback>(client, 123);
            Task <Callback>     asyncTask = asyncJob.ToTask();

            asyncJob.SetFailed(dueToRemoteFailure: false);

            Assert.True(asyncTask.IsCompleted, "Async job should be completed on message timeout");
            Assert.True(asyncTask.IsCanceled, "Async job should be canceled on message timeout");
            Assert.False(asyncTask.IsFaulted, "Async job should not be faulted on message timeout");

            await Assert.ThrowsAsync(typeof(TaskCanceledException), async() => await asyncTask);
        }
Exemplo n.º 12
0
        public static TResult RunSync <TResult>(Func <Task <TResult> > func)
        {
            var job = new AsyncJob <TResult>()
            {
                JobFunc = func, CompletedSignal = new ManualResetEventSlim(false)
            };
            var thread = new Thread(ExecuteJob <TResult>);

            thread.Start(job);
            job.CompletedSignal.Wait();
            if (job.Exception != null)
            {
                throw job.Exception;
            }
            return(job.Result);
        }
Exemplo n.º 13
0
        public static int RegisterAsyncJob <T>(AsyncJob <T> job, int callback_id, int user_id)
            where T : CallbackMsg
        {
            lock (call_id_lock)
            {
                last_call_id += 1;
                registered_calls[last_call_id] = new AsyncJobResult()
                {
                    job_id          = last_call_id,
                    internal_job_id = job.JobID,
                    finished        = false,
                    result          = null,
                };
            }

            return(last_call_id);
        }
Exemplo n.º 14
0
        private static void OnceInvoke(object state)
        {
            AsyncJob tme = state as AsyncJob;

            if (tme.WaitForNextTask())
            {
                return;
            }
            try
            {
                tme.RunTask();
            }
            catch (Exception ex)
            {
                GA.OnGlobalError(tme, ex);
                throw;
            }
        }
Exemplo n.º 15
0
        public async Task AsyncJobTimesout()
        {
            SteamClient client = new SteamClient();

            client.jobManager.SetTimeoutsEnabled(true);

            AsyncJob <Callback> asyncJob = new AsyncJob <Callback>(client, 123);

            asyncJob.Timeout = TimeSpan.FromSeconds(1);

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

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

            Assert.True(asyncTask.IsCompleted, "Async job should be completed after 5 seconds of a 1 second job timeout");
            Assert.True(asyncTask.IsCanceled, "Async job should be canceled after 5 seconds of a 1 second job timeout");
            Assert.False(asyncTask.IsFaulted, "Async job should not be faulted after 5 seconds of a 1 second job timeout");

            await Assert.ThrowsAsync(typeof(TaskCanceledException), async() => await asyncTask);
        }
Exemplo n.º 16
0
        public void AsyncJobContinuesAsynchronously()
        {
            SteamClient client = new SteamClient();

            var asyncJob  = new AsyncJob <Callback>(client, 123);
            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);
        }
Exemplo n.º 17
0
        public async Task AsyncJobContinuesAsynchronously()
        {
            SteamClient client = new SteamClient();

            var asyncJob  = new AsyncJob <Callback>(client, 123);
            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);
        }
Exemplo n.º 18
0
        public void AsyncJobGivesBackCallback()
        {
            SteamClient client = new SteamClient();

            AsyncJob<Callback> asyncJob = new AsyncJob<Callback>( client, 123 );
            Task<Callback> jobTask = asyncJob.ToTask();

            Callback ourCallback = new Callback { JobID = 123 };

            client.PostCallback( ourCallback );

            Assert.Same( jobTask.Result, ourCallback );
        }
Exemplo n.º 19
0
        public void AsyncJobThrowsExceptionOnNullCallback()
        {
            SteamClient client = new SteamClient();

            AsyncJob<Callback> asyncJob = new AsyncJob<Callback>( client, 123 );

            Assert.Throws<ArgumentNullException>( () => asyncJob.AddResult( null ) );
        }
Exemplo n.º 20
0
        public async void AsyncJobThrowsFailureExceptionOnFailure()
        {
            SteamClient client = new SteamClient();

            AsyncJob<Callback> asyncJob = new AsyncJob<Callback>( client, 123 );
            Task<Callback> asyncTask = asyncJob.ToTask();

            asyncJob.SetFailed( dueToRemoteFailure: true );

            Assert.True( asyncTask.IsCompleted, "Async job should be completed after job failure" );
            Assert.False( asyncTask.IsCanceled, "Async job should not be canceled after job failure" );
            Assert.True( asyncTask.IsFaulted, "Async job should be faulted after job failure" );

            await Assert.ThrowsAsync( typeof( AsyncJobFailedException ), async () => await asyncTask );
        }
Exemplo n.º 21
0
 public static StageSetup <TParam, TResult> Stage <TParam, TResult>(AsyncJob <TParam, TResult> job)
 {
     return(new StageSetup <TParam, TResult>(new Stage(job)));
 }
Exemplo n.º 22
0
 private void OnJobSchedulerStateChange(object _, AsyncJob __)
 {
     _UpdateDiagInfo = true;
 }
Exemplo n.º 23
0
 private void OnAsyncJobSchedulerEvent(object _, AsyncJob __)
 {
     _UpdateText = true;
 }
Exemplo n.º 24
0
        public async void AsyncJobTimesout()
        {
            SteamClient client = new SteamClient();
            client.jobManager.SetTimeoutsEnabled( true );

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

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

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

            Assert.True( asyncTask.IsCompleted, "Async job should be completed after 5 seconds of a 1 second job timeout" );
            Assert.True( asyncTask.IsCanceled, "Async job should be canceled after 5 seconds of a 1 second job timeout" );
            Assert.False( asyncTask.IsFaulted, "Async job should not be faulted after 5 seconds of a 1 second job timeout" );

            await Assert.ThrowsAsync( typeof( TaskCanceledException ), async () => await asyncTask );
        }
Exemplo n.º 25
0
 /// <summary>
 /// Tracks a job with this manager.
 /// </summary>
 /// <param name="asyncJob">The asynchronous job to track.</param>
 public void StartJob( AsyncJob asyncJob )
 {
     asyncJobs.TryAdd( asyncJob, asyncJob );
 }