Skip to content

Commit a139051

Browse files
committed
Removed SelfLog verify from tests. It is static an not deterministic when tests run in parallel.
1 parent 240901a commit a139051

File tree

2 files changed

+9
-36
lines changed

2 files changed

+9
-36
lines changed

test/Serilog.Sinks.MSSqlServer.Tests/Sinks/MSSqlServer/Platform/SqlBulkBatchWriterTests.cs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -178,62 +178,50 @@ public async Task WriteBatchClearsDataTable()
178178
}
179179

180180
[Fact]
181-
public void WriteBatchWritesSelfLogAndRethrowsIfSqlConnectionFactoryCreateThrows()
181+
public void WriteBatchRethrowsIfSqlConnectionFactoryCreateThrows()
182182
{
183183
// Arrange
184-
var selfLogWritten = false;
185-
SelfLog.Enable(w => selfLogWritten = true);
186184
_sqlConnectionFactoryMock.Setup(f => f.Create()).Callback(() => throw new Exception());
187185
var logEvents = CreateLogEvents();
188186

189187
// Act + assert
190188
Assert.ThrowsAsync<Exception>(() => _sut.WriteBatch(logEvents, _dataTable));
191-
Assert.True(selfLogWritten);
192189
}
193190

194191
[Fact]
195-
public void WriteBatchWritesSelfLogAndRethrowsIfSqlConnectionOpenAsyncThrows()
192+
public void WriteBatchRethrowsIfSqlConnectionOpenAsyncThrows()
196193
{
197194
// Arrange
198-
var selfLogWritten = false;
199-
SelfLog.Enable(w => selfLogWritten = true);
200195
_sqlConnectionWrapperMock.Setup(c => c.OpenAsync()).Callback(() => throw new Exception());
201196
var logEvents = CreateLogEvents();
202197

203198
// Act + assert
204199
Assert.ThrowsAsync<Exception>(() => _sut.WriteBatch(logEvents, _dataTable));
205-
Assert.True(selfLogWritten);
206200
}
207201

208202
[Fact]
209-
public void WriteBatchWritesSelfLogAndRethrowsIfSqlBulkCopyWriterAddSqlBulkCopyColumnMappingThrows()
203+
public void WriteBatchRethrowsIfSqlBulkCopyWriterAddSqlBulkCopyColumnMappingThrows()
210204
{
211205
// Arrange
212-
var selfLogWritten = false;
213-
SelfLog.Enable(w => selfLogWritten = true);
214206
_sqlBulkCopyWrapper.Setup(c => c.AddSqlBulkCopyColumnMapping(It.IsAny<string>(), It.IsAny<string>()))
215207
.Callback(() => throw new Exception());
216208
var logEvents = CreateLogEvents();
217209
_dataTable.Columns.Add(new DataColumn("ColumnName"));
218210

219211
// Act + assert
220212
Assert.ThrowsAsync<Exception>(() => _sut.WriteBatch(logEvents, _dataTable));
221-
Assert.True(selfLogWritten);
222213
}
223214

224215
[Fact]
225-
public void WriteBatchWritesSelfLogAndRethrowsIfSqlBulkCopyWriterWriteToServerAsyncThrows()
216+
public void WriteBatchRethrowsIfSqlBulkCopyWriterWriteToServerAsyncThrows()
226217
{
227218
// Arrange
228-
var selfLogWritten = false;
229-
SelfLog.Enable(w => selfLogWritten = true);
230219
_sqlBulkCopyWrapper.Setup(c => c.WriteToServerAsync(It.IsAny<DataTable>()))
231220
.Callback(() => throw new Exception());
232221
var logEvents = CreateLogEvents();
233222

234223
// Act + assert
235224
Assert.ThrowsAsync<Exception>(() => _sut.WriteBatch(logEvents, _dataTable));
236-
Assert.True(selfLogWritten);
237225
}
238226

239227
private static List<LogEvent> CreateLogEvents()

test/Serilog.Sinks.MSSqlServer.Tests/Sinks/MSSqlServer/Platform/SqlLogEventWriterTests.cs

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -198,53 +198,42 @@ public void WriteEventCallsLogEventDataGeneratorGetColumnsAndValuesWithLogEvent(
198198
}
199199

200200
[Fact]
201-
public void WriteEventWritesSelfLogAndRethrowsIfSqlConnectionFactoryCreateThrows()
201+
public void WriteEventRethrowsIfSqlConnectionFactoryCreateThrows()
202202
{
203203
// Arrange
204-
var selfLogWritten = false;
205-
SelfLog.Enable(w => selfLogWritten = true);
206204
_sqlConnectionFactoryMock.Setup(f => f.Create()).Callback(() => throw new Exception());
207205
var logEvent = TestLogEventHelper.CreateLogEvent();
208206

209207
// Act + assert
210208
Assert.Throws<Exception>(() => _sut.WriteEvent(logEvent));
211-
Assert.True(selfLogWritten);
212209
}
213210

214211
[Fact]
215-
public void WriteEventWritesSelfLogAndRethrowsIfSqlConnectionCreateCommandThrows()
212+
public void WriteEventRethrowsIfSqlConnectionCreateCommandThrows()
216213
{
217214
// Arrange
218-
var selfLogWritten = false;
219-
SelfLog.Enable(w => selfLogWritten = true);
220215
_sqlConnectionWrapperMock.Setup(c => c.CreateCommand()).Callback(() => throw new Exception());
221216
var logEvent = TestLogEventHelper.CreateLogEvent();
222217

223218
// Act + assert
224219
Assert.Throws<Exception>(() => _sut.WriteEvent(logEvent));
225-
Assert.True(selfLogWritten);
226220
}
227221

228222
[Fact]
229-
public void WriteEventWritesSelfLogAndRethrowsIfLogEventDataGeneratorGetColumnsAndValuesThrows()
223+
public void WriteEventRethrowsIfLogEventDataGeneratorGetColumnsAndValuesThrows()
230224
{
231225
// Arrange
232-
var selfLogWritten = false;
233-
SelfLog.Enable(w => selfLogWritten = true);
234226
_logEventDataGeneratorMock.Setup(d => d.GetColumnsAndValues(It.IsAny<LogEvent>())).Callback(() => throw new Exception());
235227
var logEvent = TestLogEventHelper.CreateLogEvent();
236228

237229
// Act + assert
238230
Assert.Throws<Exception>(() => _sut.WriteEvent(logEvent));
239-
Assert.True(selfLogWritten);
240231
}
241232

242233
[Fact]
243-
public void WriteEventWritesSelfLogAndRethrowsIfSqlCommandAddParameterThrows()
234+
public void WriteEventRethrowsIfSqlCommandAddParameterThrows()
244235
{
245236
// Arrange
246-
var selfLogWritten = false;
247-
SelfLog.Enable(w => selfLogWritten = true);
248237
_sqlCommandWrapperMock.Setup(c => c.AddParameter(It.IsAny<string>(), It.IsAny<object>())).Callback(() => throw new Exception());
249238
var fieldsAndValues = new List<KeyValuePair<string, object>> { new KeyValuePair<string, object>("FieldName1", "FieldValue1") };
250239
_logEventDataGeneratorMock.Setup(d => d.GetColumnsAndValues(It.IsAny<LogEvent>()))
@@ -253,21 +242,17 @@ public void WriteEventWritesSelfLogAndRethrowsIfSqlCommandAddParameterThrows()
253242

254243
// Act + assert
255244
Assert.Throws<Exception>(() => _sut.WriteEvent(logEvent));
256-
Assert.True(selfLogWritten);
257245
}
258246

259247
[Fact]
260-
public void WriteEventWritesSelfLogAndRethrowsIfSqlCommandExecuteNonQueryThrows()
248+
public void WriteEventRethrowsIfSqlCommandExecuteNonQueryThrows()
261249
{
262250
// Arrange
263-
var selfLogWritten = false;
264-
SelfLog.Enable(w => selfLogWritten = true);
265251
_sqlCommandWrapperMock.Setup(c => c.ExecuteNonQuery()).Callback(() => throw new Exception());
266252
var logEvent = TestLogEventHelper.CreateLogEvent();
267253

268254
// Act + assert
269255
Assert.Throws<Exception>(() => _sut.WriteEvent(logEvent));
270-
Assert.True(selfLogWritten);
271256
}
272257
}
273258
}

0 commit comments

Comments
 (0)