Skip to content

Commit adfdc0f

Browse files
committed
fix: dispose CancellationTokenSource in tests
1 parent b6449e7 commit adfdc0f

6 files changed

Lines changed: 7 additions & 7 deletions

tests/Core.Tests/Embeddings/Cache/SqliteEmbeddingCacheTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ public async Task StoreAsync_WithCancellationToken_ShouldRespectCancellation()
314314
using var cache = new SqliteEmbeddingCache(this._tempDbPath, CacheModes.ReadWrite, this._loggerMock.Object);
315315
var key = EmbeddingCacheKey.Create("OpenAI", "model", 1536, true, "test text");
316316
var vector = new float[] { 0.1f, 0.2f, 0.3f };
317-
var cts = new CancellationTokenSource();
317+
using var cts = new CancellationTokenSource();
318318
cts.Cancel();
319319

320320
// Act & Assert
@@ -328,7 +328,7 @@ public async Task TryGetAsync_WithCancellationToken_ShouldRespectCancellation()
328328
// Arrange
329329
using var cache = new SqliteEmbeddingCache(this._tempDbPath, CacheModes.ReadWrite, this._loggerMock.Object);
330330
var key = EmbeddingCacheKey.Create("OpenAI", "model", 1536, true, "test text");
331-
var cts = new CancellationTokenSource();
331+
using var cts = new CancellationTokenSource();
332332
cts.Cancel();
333333

334334
// Act & Assert

tests/Core.Tests/Embeddings/CachedEmbeddingGeneratorTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ public async Task GenerateAsync_WithCancellation_ShouldPropagate()
459459
this._cacheMock.Object,
460460
this._loggerMock.Object);
461461

462-
var cts = new CancellationTokenSource();
462+
using var cts = new CancellationTokenSource();
463463
cts.Cancel();
464464

465465
// Act & Assert

tests/Core.Tests/Embeddings/Providers/AzureOpenAIEmbeddingGeneratorTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ public async Task GenerateAsync_WithCancellation_ShouldPropagate()
228228
var generator = new AzureOpenAIEmbeddingGenerator(
229229
httpClient, "https://myservice.openai.azure.com", "deployment", "model", "key", 1536, true, this._loggerMock.Object);
230230

231-
var cts = new CancellationTokenSource();
231+
using var cts = new CancellationTokenSource();
232232
cts.Cancel();
233233

234234
// Act & Assert - TaskCanceledException inherits from OperationCanceledException

tests/Core.Tests/Embeddings/Providers/HuggingFaceEmbeddingGeneratorTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ public async Task GenerateAsync_WithCancellation_ShouldPropagate()
283283
var generator = new HuggingFaceEmbeddingGenerator(
284284
httpClient, "hf_token", "model", 384, true, null, this._loggerMock.Object);
285285

286-
var cts = new CancellationTokenSource();
286+
using var cts = new CancellationTokenSource();
287287
cts.Cancel();
288288

289289
// Act & Assert - TaskCanceledException inherits from OperationCanceledException

tests/Core.Tests/Embeddings/Providers/OllamaEmbeddingGeneratorTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ public async Task GenerateAsync_WithCancellation_ShouldPropagate()
220220
var generator = new OllamaEmbeddingGenerator(
221221
httpClient, "http://localhost:11434", "qwen3-embedding", 1024, true, this._loggerMock.Object);
222222

223-
var cts = new CancellationTokenSource();
223+
using var cts = new CancellationTokenSource();
224224
cts.Cancel();
225225

226226
// Act & Assert - TaskCanceledException inherits from OperationCanceledException

tests/Core.Tests/Embeddings/Providers/OpenAIEmbeddingGeneratorTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ public async Task GenerateAsync_WithCancellation_ShouldPropagate()
249249
var generator = new OpenAIEmbeddingGenerator(
250250
httpClient, "test-key", "model", 1536, true, null, this._loggerMock.Object);
251251

252-
var cts = new CancellationTokenSource();
252+
using var cts = new CancellationTokenSource();
253253
cts.Cancel();
254254

255255
// Act & Assert - TaskCanceledException inherits from OperationCanceledException

0 commit comments

Comments
 (0)