-
Notifications
You must be signed in to change notification settings - Fork 541
Disable JobHosting workers for disabled jobs #4752
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mikaelweave
merged 11 commits into
main
from
personal/mikaelw/disable-job-workers-for-disabled-jobs
Jun 30, 2025
Merged
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9df4b78
Disable JobHosting queues for disabled jobs
mikaelweave 766e57a
add queue type to JobHosting logging
mikaelweave aafaeb6
Merge branch 'main' into personal/mikaelw/disable-job-workers-for-dis…
mikaelweave 289bff9
combined configuration for hosting background queues and the jobs the…
mikaelweave a2dd569
updated comment
mikaelweave f56a60d
moved hosting logic config to another class
mikaelweave e45b0a1
added unit test
mikaelweave 4cf58bc
remove unneeded test file
mikaelweave e07ec31
fix casing of proj items
mikaelweave 056c394
Add using directives and traits to test class
mikaelweave 058990b
Merge branch 'personal/mikaelw/disable-job-workers-for-disabled-jobs'…
mikaelweave File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
170 changes: 170 additions & 0 deletions
170
src/Microsoft.Health.Fhir.Core.UnitTests/Config/OperationsConfigurationTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
// ------------------------------------------------------------------------------------------------- | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. | ||
// ------------------------------------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using Microsoft.Health.Fhir.Core.Configs; | ||
using Microsoft.Health.Fhir.Core.Features.Operations; | ||
using Microsoft.Health.Fhir.Tests.Common; | ||
using Microsoft.Health.Test.Utilities; | ||
using Xunit; | ||
|
||
namespace Microsoft.Health.Fhir.Core.UnitTests.Config | ||
{ | ||
[Trait(Traits.OwningTeam, OwningTeam.Fhir)] | ||
[Trait(Traits.Category, Categories.Operations)] | ||
public sealed class OperationsConfigurationTests | ||
{ | ||
[Fact] | ||
public void GivenAnOperationsConfiguration_WhenQueuesAreDisabled_RemoveThemFromTheList() | ||
{ | ||
// Arrange | ||
var operationsConfig = new OperationsConfiguration | ||
{ | ||
Export = new ExportJobConfiguration { Enabled = false }, | ||
Import = new ImportTaskConfiguration { Enabled = false }, | ||
}; | ||
|
||
operationsConfig.HostingBackgroundServiceQueues.Add(new HostingBackgroundServiceQueueItem { Queue = QueueType.Export, MaxRunningTaskCount = 2 }); | ||
operationsConfig.HostingBackgroundServiceQueues.Add(new HostingBackgroundServiceQueueItem { Queue = QueueType.Import, MaxRunningTaskCount = 2 }); | ||
operationsConfig.HostingBackgroundServiceQueues.Add(new HostingBackgroundServiceQueueItem { Queue = QueueType.BulkDelete, MaxRunningTaskCount = 1 }); | ||
|
||
// Act | ||
operationsConfig.RemoveDisabledQueues(); | ||
|
||
// Assert | ||
Assert.DoesNotContain(operationsConfig.HostingBackgroundServiceQueues, q => q.Queue == QueueType.Export); | ||
Assert.DoesNotContain(operationsConfig.HostingBackgroundServiceQueues, q => q.Queue == QueueType.Import); | ||
Assert.Contains(operationsConfig.HostingBackgroundServiceQueues, q => q.Queue == QueueType.BulkDelete); | ||
} | ||
|
||
[Fact] | ||
public void GivenAnOperationsConfiguration_WhenQueuesAreEnabledWithConnectionString_KeepThemInTheList() | ||
{ | ||
// Arrange | ||
var operationsConfig = new OperationsConfiguration | ||
{ | ||
Export = new ExportJobConfiguration { Enabled = true, StorageAccountConnection = "test-connection-string" }, | ||
Import = new ImportTaskConfiguration { Enabled = true }, | ||
IntegrationDataStore = new IntegrationDataStoreConfiguration { StorageAccountConnection = "test-connection-string" }, | ||
}; | ||
|
||
operationsConfig.HostingBackgroundServiceQueues.Add(new HostingBackgroundServiceQueueItem { Queue = QueueType.Export, MaxRunningTaskCount = 2 }); | ||
operationsConfig.HostingBackgroundServiceQueues.Add(new HostingBackgroundServiceQueueItem { Queue = QueueType.Import, MaxRunningTaskCount = 2 }); | ||
operationsConfig.HostingBackgroundServiceQueues.Add(new HostingBackgroundServiceQueueItem { Queue = QueueType.BulkDelete, MaxRunningTaskCount = 1 }); | ||
|
||
// Act | ||
operationsConfig.RemoveDisabledQueues(); | ||
|
||
// Assert | ||
Assert.Contains(operationsConfig.HostingBackgroundServiceQueues, q => q.Queue == QueueType.Export); | ||
Assert.Contains(operationsConfig.HostingBackgroundServiceQueues, q => q.Queue == QueueType.Import); | ||
Assert.Contains(operationsConfig.HostingBackgroundServiceQueues, q => q.Queue == QueueType.BulkDelete); | ||
} | ||
|
||
[Fact] | ||
public void GivenAnOperationsConfiguration_WhenQueuesAreEnabledWithUri_KeepThemInTheList() | ||
{ | ||
// Arrange | ||
var operationsConfig = new OperationsConfiguration | ||
{ | ||
Export = new ExportJobConfiguration { Enabled = true, StorageAccountUri = "https://test-account.blob.core.windows.net" }, | ||
Import = new ImportTaskConfiguration { Enabled = true }, | ||
IntegrationDataStore = new IntegrationDataStoreConfiguration { StorageAccountUri = "https://test-account.blob.core.windows.net" }, | ||
}; | ||
|
||
operationsConfig.HostingBackgroundServiceQueues.Add(new HostingBackgroundServiceQueueItem { Queue = QueueType.Export, MaxRunningTaskCount = 2 }); | ||
operationsConfig.HostingBackgroundServiceQueues.Add(new HostingBackgroundServiceQueueItem { Queue = QueueType.Import, MaxRunningTaskCount = 2 }); | ||
operationsConfig.HostingBackgroundServiceQueues.Add(new HostingBackgroundServiceQueueItem { Queue = QueueType.BulkDelete, MaxRunningTaskCount = 1 }); | ||
|
||
// Act | ||
operationsConfig.RemoveDisabledQueues(); | ||
|
||
// Assert | ||
Assert.Contains(operationsConfig.HostingBackgroundServiceQueues, q => q.Queue == QueueType.Export); | ||
Assert.Contains(operationsConfig.HostingBackgroundServiceQueues, q => q.Queue == QueueType.Import); | ||
Assert.Contains(operationsConfig.HostingBackgroundServiceQueues, q => q.Queue == QueueType.BulkDelete); | ||
} | ||
|
||
[Fact] | ||
public void GivenAnOperationsConfiguration_WhenNoQueuesExist_NoExceptionIsThrown() | ||
{ | ||
// Arrange | ||
var operationsConfig = new OperationsConfiguration | ||
{ | ||
Export = new ExportJobConfiguration { Enabled = false }, | ||
Import = new ImportTaskConfiguration { Enabled = false }, | ||
}; | ||
|
||
// Act & Assert | ||
var exception = Record.Exception(() => operationsConfig.RemoveDisabledQueues()); | ||
Assert.Null(exception); | ||
} | ||
|
||
[Fact] | ||
public void GivenAnOperationsConfiguration_WhenMixedQueuesAreEnabledOrDisabled_HandleCorrectly() | ||
{ | ||
// Arrange | ||
var operationsConfigWithExport = new OperationsConfiguration | ||
{ | ||
Export = new ExportJobConfiguration { Enabled = true, StorageAccountUri = "https://test-account.blob.core.windows.net" }, | ||
Import = new ImportTaskConfiguration { Enabled = false }, | ||
}; | ||
|
||
var operationsConfigWithImport = new OperationsConfiguration | ||
{ | ||
Export = new ExportJobConfiguration { Enabled = false }, | ||
Import = new ImportTaskConfiguration { Enabled = true}, | ||
IntegrationDataStore = new IntegrationDataStoreConfiguration { StorageAccountUri = "https://test-account.blob.core.windows.net" }, | ||
}; | ||
|
||
operationsConfigWithExport.HostingBackgroundServiceQueues.Add(new HostingBackgroundServiceQueueItem { Queue = QueueType.Export, MaxRunningTaskCount = 2 }); | ||
operationsConfigWithExport.HostingBackgroundServiceQueues.Add(new HostingBackgroundServiceQueueItem { Queue = QueueType.Import, MaxRunningTaskCount = 2 }); | ||
operationsConfigWithExport.HostingBackgroundServiceQueues.Add(new HostingBackgroundServiceQueueItem { Queue = QueueType.BulkDelete, MaxRunningTaskCount = 1 }); | ||
|
||
operationsConfigWithImport.HostingBackgroundServiceQueues.Add(new HostingBackgroundServiceQueueItem { Queue = QueueType.Export, MaxRunningTaskCount = 2 }); | ||
operationsConfigWithImport.HostingBackgroundServiceQueues.Add(new HostingBackgroundServiceQueueItem { Queue = QueueType.Import, MaxRunningTaskCount = 2 }); | ||
operationsConfigWithImport.HostingBackgroundServiceQueues.Add(new HostingBackgroundServiceQueueItem { Queue = QueueType.BulkDelete, MaxRunningTaskCount = 1 }); | ||
|
||
// Act | ||
operationsConfigWithExport.RemoveDisabledQueues(); | ||
|
||
operationsConfigWithImport.RemoveDisabledQueues(); | ||
|
||
// Assert | ||
Assert.Contains(operationsConfigWithExport.HostingBackgroundServiceQueues, q => q.Queue == QueueType.Export); | ||
Assert.DoesNotContain(operationsConfigWithExport.HostingBackgroundServiceQueues, q => q.Queue == QueueType.Import); | ||
Assert.Contains(operationsConfigWithExport.HostingBackgroundServiceQueues, q => q.Queue == QueueType.BulkDelete); | ||
|
||
Assert.Contains(operationsConfigWithImport.HostingBackgroundServiceQueues, q => q.Queue == QueueType.Import); | ||
Assert.DoesNotContain(operationsConfigWithImport.HostingBackgroundServiceQueues, q => q.Queue == QueueType.Export); | ||
Assert.Contains(operationsConfigWithImport.HostingBackgroundServiceQueues, q => q.Queue == QueueType.BulkDelete); | ||
} | ||
|
||
[Fact] | ||
public void GivenAnOperationsConfiguration_WhenStorageStringsAreEmpty_RemoveQueues() | ||
{ | ||
// Arrange | ||
var operationsConfig = new OperationsConfiguration | ||
{ | ||
Export = new ExportJobConfiguration { Enabled = true, StorageAccountConnection = string.Empty, StorageAccountUri = string.Empty }, | ||
Import = new ImportTaskConfiguration { Enabled = true }, | ||
IntegrationDataStore = new IntegrationDataStoreConfiguration { StorageAccountConnection = string.Empty, StorageAccountUri = string.Empty }, | ||
}; | ||
|
||
operationsConfig.HostingBackgroundServiceQueues.Add(new HostingBackgroundServiceQueueItem { Queue = QueueType.Export, MaxRunningTaskCount = 2 }); | ||
operationsConfig.HostingBackgroundServiceQueues.Add(new HostingBackgroundServiceQueueItem { Queue = QueueType.Import, MaxRunningTaskCount = 2 }); | ||
operationsConfig.HostingBackgroundServiceQueues.Add(new HostingBackgroundServiceQueueItem { Queue = QueueType.BulkDelete, MaxRunningTaskCount = 1 }); | ||
|
||
// Act | ||
operationsConfig.RemoveDisabledQueues(); | ||
|
||
// Assert | ||
Assert.DoesNotContain(operationsConfig.HostingBackgroundServiceQueues, q => q.Queue == QueueType.Export); | ||
Assert.DoesNotContain(operationsConfig.HostingBackgroundServiceQueues, q => q.Queue == QueueType.Import); | ||
Assert.Contains(operationsConfig.HostingBackgroundServiceQueues, q => q.Queue == QueueType.BulkDelete); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.