-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'clean-caches-2' into 'master'
Don't set exists watches if it is not necessary See merge request vostok-libraries/servicediscovery!3
- Loading branch information
Showing
10 changed files
with
280 additions
and
51 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
26 changes: 26 additions & 0 deletions
26
Vostok.ServiceDiscovery.Tests/ServiceLocatorStorage/EnvironmentStorage_TestsBase.cs
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,26 @@ | ||
using System; | ||
using FluentAssertions; | ||
using Vostok.Commons.Testing; | ||
using Vostok.ServiceDiscovery.Abstractions.Models; | ||
using Vostok.ServiceDiscovery.ServiceLocatorStorage; | ||
|
||
namespace Vostok.ServiceDiscovery.Tests.ServiceLocatorStorage; | ||
|
||
internal class EnvironmentStorage_TestsBase : TestsBase | ||
{ | ||
protected static void ShouldReturn(EnvironmentsStorage storage, string name, EnvironmentInfo info) | ||
{ | ||
Action assertion = () => { ShouldReturnImmediately(storage, name, info); }; | ||
assertion.ShouldPassIn(DefaultTimeout); | ||
} | ||
|
||
protected static void ShouldReturnImmediately(EnvironmentsStorage storage, string name, EnvironmentInfo info) | ||
{ | ||
storage.Get(name).Should().BeEquivalentTo(info); | ||
} | ||
|
||
protected EnvironmentsStorage GetEnvironmentsStorage(bool observeNonExistentEnvironment = true) | ||
{ | ||
return new EnvironmentsStorage(ZooKeeperClient, PathHelper, EventsQueue, observeNonExistentEnvironment, Log); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
....ServiceDiscovery.Tests/ServiceLocatorStorage/EnvironmentsStorageWithObserveFlag_Tests.cs
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,67 @@ | ||
using NUnit.Framework; | ||
using FluentAssertions; | ||
using Vostok.ServiceDiscovery.Abstractions.Models; | ||
|
||
namespace Vostok.ServiceDiscovery.Tests.ServiceLocatorStorage; | ||
|
||
[TestFixture] | ||
internal class EnvironmentsStorageWithObserveFlag_Tests : EnvironmentStorage_TestsBase | ||
{ | ||
[Test] | ||
public void Should_not_delete_environment_from_cache_if_node_was_deleted_when_observation_of_deleted_apps_is_enabled() | ||
{ | ||
using (var storage = GetEnvironmentsStorage(observeNonExistentEnvironment: true)) | ||
{ | ||
CreateEnvironmentNode("default", "parent"); | ||
|
||
var expectedInfo = new EnvironmentInfo("default", "parent", null); | ||
storage.Get("default").Should().BeEquivalentTo(expectedInfo); | ||
|
||
DeleteEnvironmentNode("default"); | ||
storage.UpdateAll(); | ||
storage.Contains("default").Should().BeTrue(); | ||
storage.Get("default").Should().BeNull(); | ||
|
||
CreateEnvironmentNode("default", "parent"); | ||
ShouldReturn(storage, "default", expectedInfo); | ||
} | ||
} | ||
|
||
[Test] | ||
public void Should_not_delete_environment_from_cache_when_observation_of_deleted_apps_is_disabled_and_client_disconnected() | ||
{ | ||
using (var storage = GetEnvironmentsStorage(observeNonExistentEnvironment: false)) | ||
{ | ||
CreateEnvironmentNode("default", "parent"); | ||
|
||
var expectedInfo = new EnvironmentInfo("default", "parent", null); | ||
ShouldReturnImmediately(storage, "default", expectedInfo); | ||
|
||
Ensemble.Stop(); | ||
|
||
storage.UpdateAll(); | ||
storage.Contains("default").Should().BeTrue(); | ||
ShouldReturnImmediately(storage, "default", expectedInfo); | ||
} | ||
} | ||
|
||
[Test] | ||
public void Should_delete_environment_from_cache_if_node_was_deleted_when_observation_of_deleted_apps_is_disabled() | ||
{ | ||
var expectedInfo = new EnvironmentInfo("default", "parent", null); | ||
|
||
using (var storage = GetEnvironmentsStorage(observeNonExistentEnvironment: false)) | ||
{ | ||
for (var i = 0; i < 10; i++) | ||
{ | ||
CreateEnvironmentNode("default", "parent"); | ||
|
||
ShouldReturnImmediately(storage, "default", expectedInfo); | ||
|
||
DeleteEnvironmentNode("default"); | ||
storage.UpdateAll(); | ||
storage.Contains("default").Should().BeFalse(); | ||
} | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.