-
Notifications
You must be signed in to change notification settings - Fork 485
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 #611 from martincostello/Fix-LambdaContext-Remaini…
…ngTime Fix RemainingTime returning negative values
- Loading branch information
Showing
2 changed files
with
40 additions
and
2 deletions.
There are no files selected for viewing
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
38 changes: 38 additions & 0 deletions
38
....Lambda.RuntimeSupport.Tests/Amazon.Lambda.RuntimeSupport.UnitTests/LambdaContextTests.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,38 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Globalization; | ||
using Xunit; | ||
|
||
namespace Amazon.Lambda.RuntimeSupport.UnitTests | ||
{ | ||
public class LambdaContextTests | ||
{ | ||
private readonly TestEnvironmentVariables _environmentVariables; | ||
|
||
public LambdaContextTests() | ||
{ | ||
_environmentVariables = new TestEnvironmentVariables(); | ||
} | ||
|
||
[Fact] | ||
public void RemainingTimeIsPositive() | ||
{ | ||
var deadline = DateTimeOffset.UtcNow.AddHours(1); | ||
var deadlineMs = deadline.ToUnixTimeMilliseconds().ToString(CultureInfo.InvariantCulture); | ||
|
||
var headers = new Dictionary<string, IEnumerable<string>> | ||
{ | ||
["Lambda-Runtime-Aws-Request-Id"] = new[] { Guid.NewGuid().ToString() }, | ||
["Lambda-Runtime-Deadline-Ms"] = new[] { deadlineMs }, | ||
["Lambda-Runtime-Invoked-Function-Arn"] = new[] { "my-function-arn" } | ||
}; | ||
|
||
var runtimeApiHeaders = new RuntimeApiHeaders(headers); | ||
var lambdaEnvironment = new LambdaEnvironment(_environmentVariables); | ||
|
||
var context = new LambdaContext(runtimeApiHeaders, lambdaEnvironment); | ||
|
||
Assert.True(context.RemainingTime >= TimeSpan.Zero, $"Remaining time is not a positive value: {context.RemainingTime}"); | ||
} | ||
} | ||
} |