From c72c7cce85a026af7e478649327a58f1f902153b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matt=C3=A9o=20Delucchi?= Date: Mon, 3 Jun 2024 18:43:01 +0200 Subject: [PATCH] =?UTF-8?q?fix(db):=20am=C3=A9liore=20Database.Dispose()?= =?UTF-8?q?=20et=20utilise=20using?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Server/Database.cs | 4 ++++ tests/Server.UnitTests/Database.cs | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Server/Database.cs b/src/Server/Database.cs index eda6044..5c73269 100644 --- a/src/Server/Database.cs +++ b/src/Server/Database.cs @@ -79,5 +79,9 @@ private void Clean() public void Dispose() { _cts.Cancel(); + _cts.Dispose(); + _data.Clear(); + _ex.Clear(); + GC.SuppressFinalize(this); } } \ No newline at end of file diff --git a/tests/Server.UnitTests/Database.cs b/tests/Server.UnitTests/Database.cs index bc599ac..88a315b 100644 --- a/tests/Server.UnitTests/Database.cs +++ b/tests/Server.UnitTests/Database.cs @@ -12,7 +12,7 @@ public class DatabaseTests [InlineData("", "")] public void SetGet(string key, string value) { - var db = new Database(); + using var db = new Database(); db.Set(key, value); var result = db.Get(key); Assert.Equal(value, result); @@ -23,7 +23,7 @@ public void SetGet(string key, string value) [InlineData("key2", "value", 10)] public void SetGetEx(string key, string value, long ex) { - var db = new Database(); + using var db = new Database(); db.Set(key, value, ex); var result = db.Get(key); Assert.Equal(value, result); @@ -37,7 +37,7 @@ public void SetGetEx(string key, string value, long ex) [Fact] public void AutoClean() { - var db = new Database(); + using var db = new Database(); db.Set("key1", "value"); db.Set("key2", "value", 50); db.Set("key3", "value", 20);