From eab5a7cb8f2b2247fe1c2c6c35e2d49f1eacd9c3 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 28 Jul 2022 18:09:19 +0200 Subject: [PATCH] Remove test loop. --- .../TestSuite.ApiTests/ContentUpdateTests.cs | 65 +++++++++---------- 1 file changed, 31 insertions(+), 34 deletions(-) diff --git a/backend/tools/TestSuite/TestSuite.ApiTests/ContentUpdateTests.cs b/backend/tools/TestSuite/TestSuite.ApiTests/ContentUpdateTests.cs index 137f4463b..501155105 100644 --- a/backend/tools/TestSuite/TestSuite.ApiTests/ContentUpdateTests.cs +++ b/backend/tools/TestSuite/TestSuite.ApiTests/ContentUpdateTests.cs @@ -373,52 +373,49 @@ namespace TestSuite.ApiTests [Fact] public async Task Should_update_content_in_parallel() { - for (var i = 0; i < 200; i++) + TestEntity content = null; + try { - TestEntity content = null; - try - { - // STEP 1: Create a new item. - 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 numSuccess = 0; + var numErrors = 0; + var numSuccess = 0; - // STEP 3: Make parallel updates. - await Parallel.ForEachAsync(Enumerable.Range(0, 20), async (i, ct) => + // STEP 3: Make parallel updates. + 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); - } - catch (SquidexException ex) when (ex.StatusCode is 409 or 412) - { - Interlocked.Increment(ref numErrors); - return; - } - }); + Interlocked.Increment(ref numSuccess); + } + catch (SquidexException ex) when (ex.StatusCode is 409 or 412) + { + Interlocked.Increment(ref numErrors); + return; + } + }); - // At least some errors and success should have happened. - Assert.True(numErrors > 0); - Assert.True(numSuccess > 0); + // At least some errors and success should have happened. + Assert.True(numErrors > 0); + Assert.True(numSuccess > 0); - // STEP 3: Make an normal update to ensure nothing is corrupt. - await _.Contents.UpdateAsync(content.Id, new TestEntityData { Number = 2 }); + // STEP 3: Make an normal update to ensure nothing is corrupt. + 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); - } - finally + Assert.Equal(2, content.Data.Number); + } + finally + { + if (content != null) { - if (content != null) - { - await _.Contents.DeleteAsync(content.Id); - } + await _.Contents.DeleteAsync(content.Id); } } }