Skip to content

Commit

Permalink
fix(db): améliore Database.Dispose() et utilise using
Browse files Browse the repository at this point in the history
  • Loading branch information
MattEstHaut committed Jun 3, 2024
1 parent 5aeff75 commit c72c7cc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/Server/Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,9 @@ private void Clean()
public void Dispose()
{
_cts.Cancel();
_cts.Dispose();
_data.Clear();
_ex.Clear();
GC.SuppressFinalize(this);
}
}
6 changes: 3 additions & 3 deletions tests/Server.UnitTests/Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit c72c7cc

Please sign in to comment.