Skip to content

Commit 0111f9e

Browse files
committed
Fixed the issue with conflict between tests
1 parent aafd542 commit 0111f9e

File tree

4 files changed

+28
-21
lines changed

4 files changed

+28
-21
lines changed

tests/Notion.Sharp.Tests/AppendBlocksToPageTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ public class AppendBlocksToPageTests : NotionTestsBase
1010
{
1111
[Theory]
1212
[MemberData(nameof(Blocks))]
13-
public async Task AppendChildren_Succeds(Block block)
13+
public async Task AppendChildren_Succeds(Block block) => await Retry(async () =>
1414
{
1515
var result = await SUT.AppendBlockChildrenAsync(ValidPageId,
16-
new List<Block>
17-
{
18-
block
19-
});
16+
new List<Block>
17+
{
18+
block
19+
});
2020
result.Should().NotBeNull();
2121
await SUT.DeleteBlockAsync(result.Results[0].Id);
22-
}
22+
}, 3);
2323

2424
public static TheoryData<Block> Blocks { get; } = new TheoryData<Block>
2525
{

tests/Notion.Sharp.Tests/ModelTests.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
using FluentAssertions;
2-
3-
using Notion.Model;
4-
5-
using Xunit;
6-
7-
namespace Notion.Sharp.Tests;
1+
namespace Notion.Sharp.Tests;
82

93
public class ModelTests : NotionTestsBase
104
{

tests/Notion.Sharp.Tests/NotionTestsBase.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
using Microsoft.Extensions.Configuration;
22

3-
using System;
4-
53
namespace Notion.Sharp.Tests;
64

75
public class NotionTestsBase
@@ -34,4 +32,22 @@ public NotionTestsBase()
3432
PageFromDatabase = Guid.Parse(configuration["pageFromDatabase"]);
3533
SimpleDatabase = Guid.Parse(configuration["simpleDatabase"]);
3634
}
35+
36+
public async Task Retry(Func<Task> action, int attempts)
37+
{
38+
for (var attempt = 0; attempt < attempts; attempt++)
39+
{
40+
try
41+
{
42+
await action();
43+
break;
44+
}
45+
catch (NotionException ex)
46+
{
47+
if (ex.Message == "Conflict occurred while saving. Please try again.")
48+
continue;
49+
throw;
50+
}
51+
}
52+
}
3753
}

tests/Notion.Sharp.Tests/RichTextsTests.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-

2-
using Notion.Model;
3-
4-
namespace Notion.Sharp.Tests;
1+
namespace Notion.Sharp.Tests;
52

63
public class RichTextsTests : NotionTestsBase
74
{
@@ -22,7 +19,7 @@ public async Task GetRichText(string guid)
2219

2320
[Theory]
2421
[MemberData(nameof(RichTexts))]
25-
public async Task AppendRichText_Succed(RichText richText)
22+
public async Task AppendRichText_Succed(RichText richText) => await Retry(async () =>
2623
{
2724
var result = await SUT.AppendBlockChildrenAsync(ValidPageId, new List<Block>
2825
{
@@ -35,7 +32,7 @@ public async Task AppendRichText_Succed(RichText richText)
3532
}
3633
});
3734
var block = await SUT.DeleteBlockAsync(result.Results[0].Id);
38-
}
35+
}, 3);
3936

4037
public static TheoryData<RichText> RichTexts { get; } = new TheoryData<RichText>
4138
{

0 commit comments

Comments
 (0)