Skip to content

Commit 66324c5

Browse files
Determine in which cases it fails
1 parent 06da938 commit 66324c5

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

src/NHibernate.Test/Ado/BatcherFixture.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ protected override string[] Mappings
2727
get { return new[] { "Ado.VerySimple.hbm.xml", "Ado.AlmostSimple.hbm.xml" }; }
2828
}
2929

30+
private const int BatchSize = 10;
31+
3032
protected override void Configure(Configuration configuration)
3133
{
3234
configuration.SetProperty(Environment.FormatSql, "true");
3335
configuration.SetProperty(Environment.GenerateStatistics, "true");
34-
configuration.SetProperty(Environment.BatchSize, "10");
36+
configuration.SetProperty(Environment.BatchSize, BatchSize.ToString());
3537
#if NET6_0_OR_GREATER
3638
if (_useDbBatch)
3739
{
@@ -315,19 +317,18 @@ public void InsertExactlyBatchSizeEntitiesShouldNotThrowOnCommit()
315317
// On commit, ExecuteBatch() is called, sees _batchCommand is set, and calls DoExecuteBatch
316318
// on an empty _currentBatch, causing InvalidOperationException.
317319

318-
// BatchSize is configured as 10 in this fixture
319-
const int batchSize = 10;
320-
321320
using (var session = OpenSession())
322321
using (var transaction = session.BeginTransaction())
323322
{
324-
// Insert exactly BatchSize entities - this fills the batch and triggers auto-execution
325-
for (int i = 0; i < batchSize; i++)
323+
// Insert exactly BatchSize entities - this fills the batch and triggers auto-execution.
324+
for (int i = 0; i < BatchSize; i++)
326325
{
327326
session.Save(new VerySimple { Id = 1000 + i, Name = $"Test{i}", Weight = i * 1.1 });
328327
}
329328

330-
// Commit triggers ExecuteBatch() which would fail on empty batch without the fix
329+
// Commit triggers ExecuteBatch() which would fail on empty batch without the fix,
330+
// depending on the driver. It fails with Microsoft.Data.SqlClient by example, not with
331+
// System.Data.SqlClient.
331332
transaction.Commit();
332333
}
333334

src/NHibernate.Test/Async/Ado/BatcherFixture.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,13 @@ protected override string[] Mappings
3939
get { return new[] { "Ado.VerySimple.hbm.xml", "Ado.AlmostSimple.hbm.xml" }; }
4040
}
4141

42+
private const int BatchSize = 10;
43+
4244
protected override void Configure(Configuration configuration)
4345
{
4446
configuration.SetProperty(Environment.FormatSql, "true");
4547
configuration.SetProperty(Environment.GenerateStatistics, "true");
46-
configuration.SetProperty(Environment.BatchSize, "10");
48+
configuration.SetProperty(Environment.BatchSize, BatchSize.ToString());
4749
#if NET6_0_OR_GREATER
4850
if (_useDbBatch)
4951
{
@@ -287,19 +289,18 @@ public async Task InsertExactlyBatchSizeEntitiesShouldNotThrowOnCommitAsync()
287289
// On commit, ExecuteBatch() is called, sees _batchCommand is set, and calls DoExecuteBatch
288290
// on an empty _currentBatch, causing InvalidOperationException.
289291

290-
// BatchSize is configured as 10 in this fixture
291-
const int batchSize = 10;
292-
293292
using (var session = OpenSession())
294293
using (var transaction = session.BeginTransaction())
295294
{
296-
// Insert exactly BatchSize entities - this fills the batch and triggers auto-execution
297-
for (int i = 0; i < batchSize; i++)
295+
// Insert exactly BatchSize entities - this fills the batch and triggers auto-execution.
296+
for (int i = 0; i < BatchSize; i++)
298297
{
299298
await (session.SaveAsync(new VerySimple { Id = 1000 + i, Name = $"Test{i}", Weight = i * 1.1 }));
300299
}
301300

302-
// Commit triggers ExecuteBatch() which would fail on empty batch without the fix
301+
// Commit triggers ExecuteBatch() which would fail on empty batch without the fix,
302+
// depending on the driver. It fails with Microsoft.Data.SqlClient by example, not with
303+
// System.Data.SqlClient.
303304
await (transaction.CommitAsync());
304305
}
305306

0 commit comments

Comments
 (0)