Browse Source

Remove test loop.

pull/906/head
Sebastian 4 years ago
parent
commit
eab5a7cb8f
  1. 65
      backend/tools/TestSuite/TestSuite.ApiTests/ContentUpdateTests.cs

65
backend/tools/TestSuite/TestSuite.ApiTests/ContentUpdateTests.cs

@ -373,52 +373,49 @@ namespace TestSuite.ApiTests
[Fact] [Fact]
public async Task Should_update_content_in_parallel() public async Task Should_update_content_in_parallel()
{ {
for (var i = 0; i < 200; i++) TestEntity content = null;
try
{ {
TestEntity content = null; // STEP 1: Create a new item.
try content = await _.Contents.CreateAsync(new TestEntityData { Number = 2 }, ContentCreateOptions.AsPublish);
{
// STEP 1: Create a new item.
content = await _.Contents.CreateAsync(new TestEntityData { Number = 2 }, ContentCreateOptions.AsPublish);
var numErrors = 0; var numErrors = 0;
var numSuccess = 0; var numSuccess = 0;
// STEP 3: Make parallel updates. // STEP 3: Make parallel updates.
await Parallel.ForEachAsync(Enumerable.Range(0, 20), async (i, ct) => await Parallel.ForEachAsync(Enumerable.Range(0, 20), async (i, ct) =>
{
try
{ {
try await _.Contents.UpdateAsync(content.Id, new TestEntityData { Number = i });
{
await _.Contents.UpdateAsync(content.Id, new TestEntityData { Number = i });
Interlocked.Increment(ref numSuccess); Interlocked.Increment(ref numSuccess);
} }
catch (SquidexException ex) when (ex.StatusCode is 409 or 412) catch (SquidexException ex) when (ex.StatusCode is 409 or 412)
{ {
Interlocked.Increment(ref numErrors); Interlocked.Increment(ref numErrors);
return; return;
} }
}); });
// At least some errors and success should have happened. // At least some errors and success should have happened.
Assert.True(numErrors > 0); Assert.True(numErrors > 0);
Assert.True(numSuccess > 0); Assert.True(numSuccess > 0);
// STEP 3: Make an normal update to ensure nothing is corrupt. // STEP 3: Make an normal update to ensure nothing is corrupt.
await _.Contents.UpdateAsync(content.Id, new TestEntityData { Number = 2 }); await _.Contents.UpdateAsync(content.Id, new TestEntityData { Number = 2 });
var updated = await _.Contents.GetAsync(content.Id); var updated = await _.Contents.GetAsync(content.Id);
Assert.Equal(2, content.Data.Number); Assert.Equal(2, content.Data.Number);
} }
finally finally
{
if (content != null)
{ {
if (content != null) await _.Contents.DeleteAsync(content.Id);
{
await _.Contents.DeleteAsync(content.Id);
}
} }
} }
} }

Loading…
Cancel
Save