Skip to content

Commit 8f816ee

Browse files
committed
fixed unit tests
1 parent 5cac710 commit 8f816ee

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

tests/Test/MainTest.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,21 +141,23 @@ public async Task TestUpdateEvent()
141141
}
142142
}
143143

144-
//[Fact]
144+
[Fact]
145145
public async Task TestGetEventLogStream()
146146
{
147+
var mysqlFixture = MySQLFixture.CreateMySQLFixture(3);
148+
147149
// Insert a new pet
148-
var cmd = _mysqlFixture.CreateCommand();
150+
var cmd = mysqlFixture.CreateCommand();
149151
cmd.CommandText = "INSERT INTO pet (name, owner, species, sex, birth, death) values ('Buddy', 'Alex', 'dog', 'M', '2020-01-15', NULL); SELECT LAST_INSERT_ID();";
150152
var id = (UInt64)(await cmd.ExecuteScalarAsync());
151153

152154
// Update the pet
153-
cmd = _mysqlFixture.CreateCommand();
155+
cmd = mysqlFixture.CreateCommand();
154156
cmd.CommandText = $"UPDATE pet SET owner='Sarah' WHERE id={id}";
155157
await cmd.ExecuteNonQueryAsync();
156158

157159
// Delete the pet
158-
cmd = _mysqlFixture.CreateCommand();
160+
cmd = mysqlFixture.CreateCommand();
159161
cmd.CommandText = $"DELETE FROM pet WHERE id={id}";
160162
await cmd.ExecuteNonQueryAsync();
161163

@@ -166,7 +168,7 @@ public async Task TestGetEventLogStream()
166168
var sawDelete = false;
167169

168170
// Process only the next 5 events (or fewer if we reach the end)
169-
await foreach (var logEvent in _mysqlFixture.Client.GetEventLogStream())
171+
await foreach (var logEvent in mysqlFixture.Client.GetEventLogStream())
170172
{
171173
eventCount++;
172174
_outputHelper.WriteLine($"Event type: {logEvent.EventType}");

tests/Test/MySQLFixture.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,29 @@ public class MySQLFixture : IDisposable
1313
internal const string Username = "root";
1414
internal const string Password = "root";
1515

16+
private readonly int _serverId;
17+
1618
public IReplicationClient Client { get; private set; }
1719

1820
private SemaphoreSlim _semaphore = new SemaphoreSlim(1, 1);
1921

20-
public static MySQLFixture Instance { get; } = new MySQLFixture();
22+
public static MySQLFixture Instance { get; } = new MySQLFixture(1);
23+
24+
internal static MySQLFixture CreateMySQLFixture(int serverId)
25+
{
26+
return new MySQLFixture(serverId);
27+
}
2128

22-
private MySQLFixture()
29+
private MySQLFixture(int serverId)
2330
{
31+
this._serverId = serverId;
2432
Client = new ReplicationClient();
2533
ConnectAsync().Wait();
2634
}
2735

2836
private async Task ConnectAsync()
2937
{
30-
await Client.ConnectAsync(Host, Username, Password, 1);
38+
await Client.ConnectAsync(Host, Username, Password, _serverId);
3139
}
3240

3341
private MySqlConnection GetConnection()

0 commit comments

Comments
 (0)