Skip to content

Commit

Permalink
Fix sleep period issue during multiple sequential calls (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
klaasvandeweerdt committed Aug 10, 2022
1 parent 29bef04 commit 17720e0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
7 changes: 6 additions & 1 deletion Source/Sdk4me.Tests/EventTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Linq;

namespace Sdk4me.Tests
{
Expand All @@ -9,13 +10,17 @@ public class EventTest
public void Create()
{
Sdk4meClient client = Client.Get();

Team team = client.Teams.Get().FirstOrDefault();

Request request = client.Events.Create(new RequestEvent()
{
Subject = "An API event",
Source = "api",
SourceID = "1",
Note = "A public note",
InternalNote = "An internal note"
InternalNote = "An internal note",
Team = client.Teams.Get().FirstOrDefault()
});
Assert.IsNotNull(request);
}
Expand Down
1 change: 0 additions & 1 deletion Source/Sdk4me.Tests/RequestTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public void Get()
Request request = requests[Random.Shared.Next(requests.Count)];
Trace.WriteLine($"Continue relation tests on request: #{request.ID}");


List<Note> notes = client.Requests.GetNotes(request, "*");
Assert.IsNotNull(notes);
Assert.IsInstanceOfType(notes, typeof(List<Note>));
Expand Down
10 changes: 5 additions & 5 deletions Source/Sdk4me/Base/Sleep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Sdk4me
/// </summary>
internal static class Sleep
{
private const int minimumDurationPerRequestInMiliseconds = 116;
private const int minimumDurationPerRequestInMiliseconds = 100;
private static int startTickCount = 0;

/// <summary>
Expand All @@ -20,7 +20,7 @@ public static void RegisterStartTime()
}

/// <summary>
/// Puts the current thread in sleep for 116 milliseconds minus the elapsed milliseconds between now an the value stored via the <see cref="RegisterStartTime"/> method.
/// Puts the current thread in sleep for 100 milliseconds minus the elapsed milliseconds between now an the value stored via the <see cref="RegisterStartTime"/> method.
/// </summary>
public static void SleepRemainingTime()
{
Expand All @@ -32,9 +32,9 @@ public static void SleepRemainingTime()
}
else
{
int sleepTicks = minimumDurationPerRequestInMiliseconds - endTickCount - startTickCount;
if (sleepTicks > 0)
Thread.Sleep(sleepTicks);
long sleepTime = minimumDurationPerRequestInMiliseconds - ((endTickCount - startTickCount) / TimeSpan.TicksPerSecond);
if (sleepTime > 0 && sleepTime <= minimumDurationPerRequestInMiliseconds)
Thread.Sleep(Convert.ToInt32(sleepTime));
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions Source/Sdk4me/Sdk4me.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@

<PropertyGroup>
<LangVersion>7.3</LangVersion>
<AssemblyVersion>2.0.3.1</AssemblyVersion>
<FileVersion>2.0.3.1</FileVersion>
<AssemblyVersion>2.0.3.2</AssemblyVersion>
<FileVersion>2.0.3.2</FileVersion>
<AnalysisLevel>6.0</AnalysisLevel>
<Authors>Klaas Vandeweerdt</Authors>
<Description>A .NET client for accessing the 4me v1 REST API</Description>
<Copyright>MIT License</Copyright>
<Version>2.0.3.1</Version>
<Version>2.0.3.2</Version>
<ProduceReferenceAssembly>True</ProduceReferenceAssembly>
<RepositoryType>git</RepositoryType>
<PackageIcon>LogoDark128x218.png</PackageIcon>
Expand Down

0 comments on commit 17720e0

Please sign in to comment.