-
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Use namespace and name for requeueing of entities (#801)
Fixes #800
- Loading branch information
1 parent
d408fe0
commit de986bf
Showing
2 changed files
with
68 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 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,49 @@ | ||
using k8s.Models; | ||
|
||
using KubeOps.Operator.Queue; | ||
|
||
namespace KubeOps.Operator.Test.Queue; | ||
|
||
public class TimedEntityQueueTest | ||
{ | ||
[Fact] | ||
public async Task Can_Enqueue_Multiple_Entities_With_Same_Name() | ||
{ | ||
var queue = new TimedEntityQueue<V1Secret>(); | ||
|
||
queue.Enqueue(CreateSecret("app-ns1", "secret-name"), TimeSpan.FromSeconds(1)); | ||
queue.Enqueue(CreateSecret("app-ns2", "secret-name"), TimeSpan.FromSeconds(1)); | ||
|
||
var items = new List<V1Secret>(); | ||
|
||
var tokenSource = new CancellationTokenSource(); | ||
tokenSource.CancelAfter(TimeSpan.FromSeconds(2)); | ||
|
||
var enumerator = queue.GetAsyncEnumerator(tokenSource.Token); | ||
|
||
try | ||
{ | ||
while (await enumerator.MoveNextAsync()) | ||
{ | ||
items.Add(enumerator.Current); | ||
} | ||
} | ||
catch (OperationCanceledException) | ||
{ | ||
// We expect to timeout watching the queue so that we can assert the items received | ||
} | ||
|
||
Assert.Equal(2, items.Count); | ||
} | ||
|
||
private V1Secret CreateSecret(string secretNamespace, string secretName) | ||
{ | ||
var secret = new V1Secret(); | ||
secret.EnsureMetadata(); | ||
|
||
secret.Metadata.SetNamespace(secretNamespace); | ||
secret.Metadata.Name = secretName; | ||
|
||
return secret; | ||
} | ||
} |