Rename AcquireJobRequest::StreamID to AcquireJobRequest::JobMessageID (#2547)

* Rename AcquireJobRequest::StreamID to AcquireJobRequest::JobMessageID to match corresponding server-side update.
* appeased the linter
* Added unit tests to prove AcquireJobRequest serialization/deserialization is as-expected.
* Distinguish unit test variations.
* Incorporated PR Feedback.
This commit is contained in:
John Wesley Walker III
2023-04-26 18:31:41 +02:00
committed by GitHub
parent c4d41e95cb
commit a41397ae93
3 changed files with 72 additions and 5 deletions

View File

@@ -1,13 +1,16 @@
using System.Collections.Generic;
using System.Runtime.Serialization; using System.Runtime.Serialization;
using GitHub.DistributedTask.WebApi;
namespace GitHub.Actions.RunService.WebApi namespace GitHub.Actions.RunService.WebApi
{ {
[DataContract] [DataContract]
public class AcquireJobRequest public class AcquireJobRequest
{ {
[DataMember(Name = "jobMessageId", EmitDefaultValue = false)]
public string JobMessageId { get; set; }
// This field will be removed in an upcoming Runner release.
// It's left here temporarily to facilitate the transition to the new field name, JobMessageId.
[DataMember(Name = "streamId", EmitDefaultValue = false)] [DataMember(Name = "streamId", EmitDefaultValue = false)]
public string StreamID { get; set; } public string StreamId { get; set; }
} }
} }

View File

@@ -64,7 +64,8 @@ namespace GitHub.Actions.RunService.WebApi
HttpMethod httpMethod = new HttpMethod("POST"); HttpMethod httpMethod = new HttpMethod("POST");
var payload = new AcquireJobRequest var payload = new AcquireJobRequest
{ {
StreamID = messageId JobMessageId = messageId,
StreamId = messageId,
}; };
requestUri = new Uri(requestUri, "acquirejob"); requestUri = new Uri(requestUri, "acquirejob");

View File

@@ -0,0 +1,63 @@
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization.Json;
using System.Text;
using Xunit;
namespace GitHub.Actions.RunService.WebApi.Tests;
public sealed class AcquireJobRequestL0
{
[Fact]
[Trait("Level", "L0")]
[Trait("Category", "Common")]
public void VerifySerialization()
{
var jobMessageId = "1526919030369-33";
var request = new AcquireJobRequest
{
JobMessageId = jobMessageId,
StreamId = jobMessageId
};
var serializer = new DataContractJsonSerializer(typeof(AcquireJobRequest));
using var stream = new MemoryStream();
serializer.WriteObject(stream, request);
stream.Position = 0;
using var reader = new StreamReader(stream, Encoding.UTF8);
string json = reader.ReadToEnd();
string expected = DoubleQuotify(string.Format("{{'jobMessageId':'{0}','streamId':'{0}'}}", request.JobMessageId));
Assert.Equal(expected, json);
}
[Fact]
[Trait("Level", "L0")]
[Trait("Category", "Common")]
public void VerifyDeserialization()
{
var serializer = new DataContractJsonSerializer(typeof(AcquireJobRequest));
var variations = new Dictionary<string, string>()
{
["{'streamId': 'legacy', 'jobMessageId': 'new-1'}"] = "new-1",
["{'jobMessageId': 'new-2', 'streamId': 'legacy'}"] = "new-2",
["{'jobMessageId': 'new-3'}"] = "new-3"
};
foreach (var (source, expected) in variations)
{
using var stream = new MemoryStream();
stream.Write(Encoding.UTF8.GetBytes(DoubleQuotify(source)));
stream.Position = 0;
var recoveredRecord = serializer.ReadObject(stream) as AcquireJobRequest;
Assert.NotNull(recoveredRecord);
Assert.Equal(expected, recoveredRecord.JobMessageId);
}
}
private static string DoubleQuotify(string text)
{
return text.Replace('\'', '"');
}
}