Exemple #1
0
    public Task JobStore_Next_ShouldSucceed()
    {
        return(SqliteInMemoryHelper.UsingSculleryContextAsync(async context =>
        {
            var jobStore = new EntityFrameworkJobStore(context);
            var jobManager = new JobManager(jobStore);
            var jobRunner = new JobRunner(null !);

            await jobManager.EnqueueAsync(() => TestJobs.Job1(1));
            await jobManager.EnqueueAsync(() => TestJobs.Job1(2));

            var tokenSource = new CancellationTokenSource();

            JobDescriptor?job1 = await jobStore.NextAsync(tokenSource.Token);
            Assert.NotNull(job1);
            Assert.Equal("1", job1 !.Id);

            JobDescriptor?job2 = await jobStore.NextAsync(tokenSource.Token);
            Assert.NotNull(job2);
            Assert.Equal("2", job2 !.Id);

            tokenSource.Cancel();

            JobDescriptor?job3 = await jobStore.NextAsync(tokenSource.Token);
            Assert.Null(job3);
        }));
    }
Exemple #2
0
    public Task JobRunner_ParentModel1_ShouldSucceed()
    {
        return(SqliteInMemoryHelper.UsingSculleryContextAsync(async context =>
        {
            var jobStore = new EntityFrameworkJobStore(context);
            var jobManager = new JobManager(jobStore);
            var jobRunner = new JobRunner(null !);

            ParentModel model1 = TestJobs.CreateParentModel1();
            await jobManager.EnqueueAsync(() => TestJobs.ParentModelJob1(model1));

            JobDescriptor?job1 = await jobStore.NextAsync(CancellationToken.None);
            Assert.NotNull(job1);

            // The job contains the test assertions.
            await jobRunner.RunAsync(job1 !.Call, CancellationToken.None);
        }));
    }
    public Task Adapter_TryClaimJob_ShouldSucceed()
    {
        return(SqliteInMemoryHelper.UsingSculleryContextAsync(async context =>
        {
            var storeAdapter = new SqlJobStoreAdapter(context);
            var testStore = new EntityFrameworkJobStore(context, null, storeAdapter);
            var jobManager = new JobManager(testStore);
            var jobRunner = new JobRunner(null !);

            await jobManager.EnqueueAsync(() => TestJobs.Job1(1));
            await jobManager.EnqueueAsync(() => TestJobs.Job1(2));

            Job?job1 = await storeAdapter.GetCandidateJobAsync();
            Job?job2 = await storeAdapter.GetCandidateJobAsync();

            bool result1 = await storeAdapter.TryClaimJobAsync(job1 !);
            Assert.True(result1); // Claim succeeded

            bool result2 = await storeAdapter.TryClaimJobAsync(job2 !);
            Assert.False(result2); // Claim failed
        }));
    }