Skip to content

Commit

Permalink
JoScheduler: tests not pass always
Browse files Browse the repository at this point in the history
  • Loading branch information
apobekiaris committed Nov 15, 2021
1 parent 54c0017 commit e70f6c5
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 105 deletions.
4 changes: 2 additions & 2 deletions Build/check-tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ Invoke-Script {
throw "There are fail tests in $DxPipelineBuildId"
}
if ($env:CustomVersion -eq (Get-XAFLatestMinors -Source $DXApiFeed | Select-Object -First 1) -and $Publish) {
$failedBuilds = Get-XAFLatestMinors -Source $env:DxFeed|Where-Object{$_ -gt "20.1.0"} | ForEach-Object {
$build = Get-AzBuilds -Definition Reactive.XAF-Lab-Tests -Tag "$_" -Top 1 -BranchName $env:Build_SourceBranchName
$failedBuilds = Get-XAFLatestMinors -Source $env:DxFeed|Select-Object -First 1|Where-Object{$_ -gt "20.1.0"} | ForEach-Object {
$build = Get-AzBuilds -Definition Reactive.XAF-Lab-Tests -Tag "$_" -Top 1 -BranchName master
Get-AzTestRuns -buildIds $build.Id -FailedOnly
}
"failedBuilds=$failedBuilds"
Expand Down

This file was deleted.

35 changes: 0 additions & 35 deletions src/Modules/LookupDefaultObject/Properties/AssemblyInfo.cs

This file was deleted.

2 changes: 0 additions & 2 deletions src/Tests/JobScheduler.Hangfire/ChainJobTests.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
using System.Linq;
using System.Reactive.Linq;
using System.Threading;
using System.Threading.Tasks;
using akarnokd.reactive_extensions;
using Hangfire;
using NUnit.Framework;
using Shouldly;
using Xpand.Extensions.Blazor;
using Xpand.Extensions.Reactive.Utility;
using Xpand.TestsLib.Common.Attributes;
using Xpand.XAF.Modules.JobScheduler.Hangfire.BusinessObjects;
using Xpand.XAF.Modules.JobScheduler.Hangfire.Tests.Common;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using DevExpress.ExpressApp.Blazor;
using Hangfire;
using Hangfire.MemoryStorage;
using Hangfire.MemoryStorage.Database;
using Xpand.Extensions.TypeExtensions;
using Xpand.TestsLib.Blazor;
using Xpand.TestsLib.Common;
Expand All @@ -17,7 +16,7 @@ namespace Xpand.XAF.Modules.JobScheduler.Hangfire.Tests.Common {
public abstract class JobSchedulerCommonTest : BlazorCommonTest {
public override void Setup() {
base.Setup();
GlobalConfiguration.Configuration.UseMemoryStorage(new MemoryStorageOptions(),new Data());
GlobalConfiguration.Configuration.UseMemoryStorage(new MemoryStorageOptions());
}

public override void Dispose() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public JobSchedulerStartup(IConfiguration configuration) : base(configuration) {

public override void ConfigureServices(IServiceCollection services) {
base.ConfigureServices(services);
services.AddSingleton<IHangfireJobFilter>(provider => new HangfireJobFilter(provider));
services.AddSingleton<IHangfireJobFilter,HangfireJobFilter>();
services.AddSingleton<IBackgroundProcessingServer, BackgroundProcessingServer>();
}
}

Expand Down
55 changes: 31 additions & 24 deletions src/Tests/JobScheduler.Hangfire/JobSchedulerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
using System.Linq;
using System.Reactive.Linq;
using System.Threading;
using System.Threading.Tasks;
using akarnokd.reactive_extensions;
using NUnit.Framework;
using Shouldly;
using Xpand.Extensions.Blazor;
using Xpand.Extensions.Reactive.Utility;
using Xpand.Extensions.XAF.FrameExtensions;
using Xpand.Extensions.XAF.XafApplicationExtensions;
using Xpand.TestsLib.Common;
Expand All @@ -16,16 +18,20 @@
namespace Xpand.XAF.Modules.JobScheduler.Hangfire.Tests{
[NonParallelizable]
public class JobSchedulerTests:JobSchedulerCommonTest{

public override void Setup() {
base.Setup();
Timeout=TimeSpan.FromSeconds(15);
}

[TestCase(typeof(TestJobDI))]
[TestCase(typeof(TestJob))]
[XpandTest()][Order(0)]
public void Inject_BlazorApplication_In_JobType_Ctor(Type testJobType) {
using var jobs = TestJob.Jobs.FirstAsync().Test();
public async Task Inject_BlazorApplication_In_JobType_Ctor(Type testJobType) {
var jobs = TestJob.Jobs.FirstAsync().ReplayConnect();
using var application = JobSchedulerModule().Application.ToBlazor();
application.CommitNewJob(testJobType).Trigger();

var testJob = jobs.AwaitDone(Timeout).Items.First();
var testJob =await jobs.Timeout(Timeout);

if (testJobType==typeof(TestJobDI)) {
testJob.Provider.ShouldNotBeNull();
Expand All @@ -40,7 +46,7 @@ public void Inject_BlazorApplication_In_JobType_Ctor(Type testJobType) {
[XpandTest()][Order(100)]
public void Customize_Job_Schedule(bool newObject) {

using var application = JobSchedulerModule().Application;
using var application = JobSchedulerModule().Application.ToBlazor();
var objectSpace = application.CreateObjectSpace();

var scheduledJob = objectSpace.CreateObject<Job>();
Expand All @@ -61,32 +67,34 @@ public void Customize_Job_Schedule(bool newObject) {

[Test()][Apartment(ApartmentState.MTA)]
[XpandTest()][Order(200)]
public void Inject_PerformContext_In_JobType_Method() {
using var jobs = TestJob.Jobs.FirstAsync().Test();
public async Task Inject_PerformContext_In_JobType_Method() {
var jobs = TestJob.Jobs.FirstAsync().ReplayConnect();
using var application = JobSchedulerModule().Application.ToBlazor();

var job = application.CommitNewJob(typeof(TestJob),nameof(TestJob.TestJobId)).Trigger();

var testJob = jobs.AwaitDone(Timeout).Items.First();

var testJob = await jobs.Timeout(Timeout);


testJob.Context.ShouldNotBeNull();
testJob.Context.JobId().ShouldBe(job.Id);
var objectSpace = application.CreateObjectSpace();
job = objectSpace.GetObject(job);
job.JobMethods.Count.ShouldBeGreaterThan(0);
job.JobMethods.Count.ShouldBeGreaterThan(0);

}


[Test][Apartment(ApartmentState.STA)]
[XpandTest()]
[Order(300)]
public void Schedule_Successful_job() {
public async Task Schedule_Successful_job() {
using var application = JobSchedulerModule().Application.ToBlazor();
using var testObserver = WorkerState.Succeeded.Executed().Test();
var testObserver = WorkerState.Succeeded.Executed().FirstAsync().ReplayConnect();

application.CommitNewJob().Trigger();

var jobState = testObserver.AwaitDone(Timeout).Items.First();
var jobState = await testObserver.Timeout(Timeout);

var objectSpace = application.CreateObjectSpace();
jobState=objectSpace.GetObjectByKey<JobState>(jobState.Oid);
Expand All @@ -99,7 +107,7 @@ public void Schedule_Successful_job() {

}

[XpandTest()][Test][Order(600)]
[XpandTest()][Test][Order(Int32.MaxValue)]
public void Pause_Job() {
using var application = JobSchedulerModule().Application.ToBlazor();
using var jobsObserver = TestJob.Jobs.Timeout(Timeout).FirstAsync().Test();
Expand All @@ -110,13 +118,13 @@ public void Pause_Job() {
}

[XpandTest()][Test][Order(700)]
public void Resume_Job() {
public async Task Resume_Job() {
using var application = JobSchedulerModule().Application.ToBlazor();
using var jobsCommitObserver = TestJob.Jobs.Timeout(Timeout).FirstAsync().Test();
var jobsCommitObserver = TestJob.Jobs.Timeout(Timeout).FirstAsync().ReplayConnect();

application.CommitNewJob().Pause().Resume().Trigger();

jobsCommitObserver.AwaitDone(Timeout).ItemCount.ShouldBe(1);
await jobsCommitObserver.Timeout(Timeout);

}

Expand Down Expand Up @@ -164,19 +172,18 @@ public void JobResume_Action() {
viewWindow.Action<JobSchedulerModule>().PauseJob().Active.ResultValue.ShouldBeTrue();
}

[TestCase(nameof(TestJob.FailMethodNoRetry),1)]

[TestCase(nameof(TestJob.FailMethodRetry),2)]
[XpandTest()][Order(1000)]
public void Schedule_Failed_Recurrent_job(string methodName,int executions) {
public async Task Schedule_Failed_Recurrent_job(string methodName,int executions) {
using var application = JobSchedulerModule().Application.ToBlazor();
var testObserver = JobSchedulerService.JobState.FirstAsync(state => state.State==WorkerState.Failed).Test();
var testObserver = JobSchedulerService.JobState.FirstAsync(state => state.State==WorkerState.Failed).ReplayConnect();
application.CommitNewJob(methodName:methodName).Trigger();

using var observer = testObserver.AwaitDone(Timeout*3);
observer.ItemCount.ShouldBe(1);

var observer = await testObserver.Timeout(Timeout*3);

var objectSpace = application.CreateObjectSpace();
var jobState = objectSpace.GetObject(observer.Items.Last());
var jobState = objectSpace.GetObject(observer);
jobState.JobWorker.ExecutionsCount.ShouldBe(executions);
}
}
Expand Down

0 comments on commit e70f6c5

Please sign in to comment.