-
Notifications
You must be signed in to change notification settings - Fork 287
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1490 from microsoft/develop
merge DEVELOP to MASTER (prep 2.12 stable)
- Loading branch information
Showing
54 changed files
with
634 additions
and
512 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Fix Issue # . | ||
<Short description of the fix.> | ||
|
||
- [ ] I ran Unit Tests locally. | ||
- [ ] CHANGELOG.md updated with one line description of the fix, and a link to the original issue if available. | ||
|
||
For significant contributions please make sure you have completed the following items: | ||
|
||
- [ ] Design discussion issue # | ||
- [ ] Changes in public surface reviewed | ||
- [ ] CHANGELOG.md updated with one line description of the fix, and a link to the original issue. | ||
|
||
The PR will trigger build, unit tests, and functional tests automatically. Please follow [these](https://github.com/Microsoft/ApplicationInsights-dotnet/blob/develop/.github/CONTRIBUTING.md) instructions to build and test locally. | ||
|
||
Notes for reviewers: | ||
|
||
- We support [comment build triggers](https://docs.microsoft.com/azure/devops/pipelines/repos/github?view=azure-devops&tabs=yaml#comment-triggers) | ||
- `/AzurePipelines run` will queue all builds | ||
- `/AzurePipelines run <pipeline-name>` will queue a specific build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
BASE/Test/Microsoft.ApplicationInsights.Test/Shared/Common/InterlockedThrottleTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
namespace Microsoft.ApplicationInsights.Common | ||
{ | ||
using System; | ||
using System.Threading; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
[TestClass] | ||
public class InterlockedThrottleTests | ||
{ | ||
[TestMethod] | ||
public void VerifyInterlockedWorksAsExpected() | ||
{ | ||
int testInterval = 10; | ||
var counter = 0; | ||
|
||
var its = new InterlockedThrottle(TimeSpan.FromSeconds(testInterval)); | ||
|
||
its.PerformThrottledAction(() => counter++); | ||
its.PerformThrottledAction(() => counter++); | ||
its.PerformThrottledAction(() => counter++); | ||
its.PerformThrottledAction(() => counter++); | ||
|
||
Assert.AreEqual(1, counter); | ||
|
||
Thread.Sleep(TimeSpan.FromSeconds(testInterval +1)); | ||
|
||
its.PerformThrottledAction(() => counter++); | ||
its.PerformThrottledAction(() => counter++); | ||
its.PerformThrottledAction(() => counter++); | ||
its.PerformThrottledAction(() => counter++); | ||
|
||
Assert.AreEqual(2, counter); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
namespace Microsoft.ApplicationInsights.Common | ||
{ | ||
using System; | ||
using System.Threading; | ||
|
||
/// <summary> | ||
/// This class will hold a timestamp and will perform a given action only if the current time has exceeded an interval. | ||
/// </summary> | ||
internal class InterlockedThrottle | ||
{ | ||
private readonly TimeSpan interval; | ||
private long timeStamp = DateTimeOffset.MinValue.Ticks; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="InterlockedThrottle"/> class. | ||
/// </summary> | ||
/// <param name="interval">Defines the time period to perform some action.</param> | ||
public InterlockedThrottle(TimeSpan interval) => this.interval = interval; | ||
|
||
/// <summary> | ||
/// Will execute the action only if the time period has elapsed. | ||
/// </summary> | ||
/// <param name="action">Action to be executed.</param> | ||
public void PerformThrottledAction(Action action) | ||
{ | ||
var now = DateTimeOffset.UtcNow; | ||
if (now.Ticks > Interlocked.Read(ref this.timeStamp)) | ||
{ | ||
Interlocked.Exchange(ref this.timeStamp, now.Add(this.interval).Ticks); | ||
action(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.