Skip to content

Commit 10f39c9

Browse files
committed
Fix tests that don't correspond to their method name
Fix event source listener test so it is ok with the trace from the unobserved exception
1 parent 3f5cfa9 commit 10f39c9

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

src/Microsoft.Data.SqlClient/tests/ManualTests/TracingTests/EventSourceTest.cs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
using System.Collections.Generic;
56
using System.Linq;
67
using Xunit;
78

@@ -12,22 +13,28 @@ public class EventSourceTest
1213
[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))]
1314
public void EventSourceTestAll()
1415
{
15-
using DataTestUtility.MDSEventListener TraceListener = new();
16-
using (SqlConnection connection = new(DataTestUtility.TCPConnectionString))
16+
using DataTestUtility.MDSEventListener traceListener = new();
17+
18+
using SqlConnection connection = new(DataTestUtility.TCPConnectionString);
19+
connection.Open();
20+
21+
using SqlCommand command = new("SELECT @@VERSION", connection);
22+
using SqlDataReader reader = command.ExecuteReader();
23+
while (reader.Read())
1724
{
18-
connection.Open();
19-
using SqlCommand command = new("SELECT @@VERSION", connection);
20-
using SqlDataReader reader = command.ExecuteReader();
21-
while (reader.Read())
22-
{
23-
// Flush data
24-
}
25+
// Flush data
2526
}
2627

27-
// Need to investigate better way of validating traces in sequential runs,
28-
// For now we're collecting all traces to improve code coverage.
28+
// TODO: Need to investigate better way of validating traces in sequential runs, for now we're collecting all traces to improve code coverage.
2929

30-
Assert.All(TraceListener.IDs, item => { Assert.Contains(item, Enumerable.Range(1, 21)); });
30+
// Assert
31+
// - Collected trace event IDs are in the range of official trace event IDs
32+
// @TODO: This is brittle, refactor the SqlClientEventSource code so the event IDs it can throw are accessible here
33+
HashSet<int> acceptableEventIds = new HashSet<int>(Enumerable.Range(0, 21));
34+
foreach (int id in traceListener.IDs)
35+
{
36+
Assert.Contains(id, acceptableEventIds);
37+
}
3138
}
3239
}
3340
}

src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/Utilities/AsyncHelperTest.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -477,19 +477,21 @@ public async Task ContinueTaskWithState_2Generics_TaskCompletesHandlerThrows()
477477
Task taskToContinue = Task.CompletedTask;
478478
TaskCompletionSource<object?> taskCompletionSource = GetTaskCompletionSource();
479479
const int state1 = 123;
480+
const int state2 = 234
480481

481482
// - mockOnSuccess handler throws
482-
Mock<Action<int>> mockOnSuccess = new();
483-
mockOnSuccess.Setup(o => o(It.IsAny<int>())).Throws<Exception>();
483+
Mock<Action<int, int>> mockOnSuccess = new();
484+
mockOnSuccess.Setup(o => o(It.IsAny<int>(), It.IsAny<int>())).Throws<Exception>();
484485

485-
Mock<Action<int, Exception>> mockOnFailure = new();
486-
Mock<Action<int>> mockOnCancellation = new();
486+
Mock<Action<int, int, Exception>> mockOnFailure = new();
487+
Mock<Action<int, int>> mockOnCancellation = new();
487488

488489
// Act
489490
AsyncHelper.ContinueTaskWithState(
490491
taskToContinue,
491492
taskCompletionSource,
492493
state1,
494+
state2,
493495
mockOnSuccess.Object,
494496
mockOnFailure.Object,
495497
mockOnCancellation.Object);
@@ -500,7 +502,7 @@ public async Task ContinueTaskWithState_2Generics_TaskCompletesHandlerThrows()
500502
Assert.Equal(TaskStatus.Faulted, taskCompletionSource.Task.Status);
501503

502504
// - mockOnSuccess was called with state obj
503-
mockOnSuccess.Verify(action => action(state1), Times.Once);
505+
mockOnSuccess.Verify(action => action(state1, state2), Times.Once);
504506
mockOnFailure.VerifyNeverCalled();
505507
mockOnCancellation.VerifyNeverCalled();
506508
}

0 commit comments

Comments
 (0)