Skip to content

Commit 3d56db4

Browse files
committed
[ECO-4567] Fixed MsgPackSerializer tests with proper logging
- Added extra MsgPack tests to MessageEncodersAcceptanceTests - Update Base64EncoderTests with Encode specific tests - Removed unncessary Defaults.MsgPackEnabled checks from test fixtures - Removed unncessary mono build step from CI since its irrelevant (we already support netstandard2.0)
1 parent 477e4d9 commit 3d56db4

File tree

11 files changed

+373
-228
lines changed

11 files changed

+373
-228
lines changed

.github/workflows/run-tests-macos-mono.yml

Lines changed: 0 additions & 37 deletions
This file was deleted.

cake-build/tasks/test.cake

Lines changed: 82 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Task("_NetFramework_Unit_Tests_WithRetry")
2626

2727
var resultsPath = paths.TestResults.CombineWithFilePath("xunit-netframework-unit.xml");
2828

29+
var initialFailedTests = new List<string>();
2930
try
3031
{
3132
var settings = testExecutionHelper.CreateXUnitSettings("xunit-netframework-unit", isIntegration: false);
@@ -34,20 +35,31 @@ Task("_NetFramework_Unit_Tests_WithRetry")
3435
catch
3536
{
3637
Warning("Some tests failed. Retrying failed tests...");
38+
initialFailedTests = testRetryHelper.FindFailedXUnitTests(resultsPath);
3739
}
3840

39-
testExecutionHelper.RetryFailedXUnitTests(
40-
testAssemblies,
41-
resultsPath,
42-
testRetryHelper,
43-
(test) => testExecutionHelper.CreateXUnitSettings("retry", isIntegration: false, isRetry: true)
44-
);
45-
46-
// Check if any tests still failed after retry
47-
var stillFailedTests = testRetryHelper.FindFailedXUnitTests(resultsPath);
48-
if (stillFailedTests.Any())
41+
if (initialFailedTests.Any())
4942
{
50-
throw new Exception($"{stillFailedTests.Count} test(s) failed after retry");
43+
testExecutionHelper.RetryFailedXUnitTests(
44+
testAssemblies,
45+
resultsPath,
46+
testRetryHelper,
47+
(test) => testExecutionHelper.CreateXUnitSettings("retry", isIntegration: false, isRetry: true)
48+
);
49+
50+
// Check retry result files to see if tests still failed
51+
var stillFailedTests = new List<string>();
52+
for (int i = 1; i <= initialFailedTests.Count; i++)
53+
{
54+
var retryResultsPath = paths.TestResults.CombineWithFilePath($"xunit-netframework-unit-{i}.xml");
55+
var retryFailed = testRetryHelper.FindFailedXUnitTests(retryResultsPath);
56+
stillFailedTests.AddRange(retryFailed);
57+
}
58+
59+
if (stillFailedTests.Any())
60+
{
61+
throw new Exception($"{stillFailedTests.Count} test(s) failed after retry");
62+
}
5163
}
5264
});
5365

@@ -75,6 +87,7 @@ Task("_NetFramework_Integration_Tests_WithRetry")
7587

7688
var resultsPath = paths.TestResults.CombineWithFilePath("xunit-netframework-integration.xml");
7789

90+
var initialFailedTests = new List<string>();
7891
try
7992
{
8093
var settings = testExecutionHelper.CreateXUnitSettings("xunit-netframework-integration", isIntegration: true);
@@ -83,20 +96,31 @@ Task("_NetFramework_Integration_Tests_WithRetry")
8396
catch
8497
{
8598
Warning("Some tests failed. Retrying failed tests...");
99+
initialFailedTests = testRetryHelper.FindFailedXUnitTests(resultsPath);
86100
}
87101

88-
testExecutionHelper.RetryFailedXUnitTests(
89-
testAssemblies,
90-
resultsPath,
91-
testRetryHelper,
92-
(test) => testExecutionHelper.CreateXUnitSettings("retry", isIntegration: true, isRetry: true)
93-
);
94-
95-
// Check if any tests still failed after retry
96-
var stillFailedTests = testRetryHelper.FindFailedXUnitTests(resultsPath);
97-
if (stillFailedTests.Any())
102+
if (initialFailedTests.Any())
98103
{
99-
throw new Exception($"{stillFailedTests.Count} test(s) failed after retry");
104+
testExecutionHelper.RetryFailedXUnitTests(
105+
testAssemblies,
106+
resultsPath,
107+
testRetryHelper,
108+
(test) => testExecutionHelper.CreateXUnitSettings("retry", isIntegration: true, isRetry: true)
109+
);
110+
111+
// Check retry result files to see if tests still failed
112+
var stillFailedTests = new List<string>();
113+
for (int i = 1; i <= initialFailedTests.Count; i++)
114+
{
115+
var retryResultsPath = paths.TestResults.CombineWithFilePath($"xunit-netframework-integration-{i}.xml");
116+
var retryFailed = testRetryHelper.FindFailedXUnitTests(retryResultsPath);
117+
stillFailedTests.AddRange(retryFailed);
118+
}
119+
120+
if (stillFailedTests.Any())
121+
{
122+
throw new Exception($"{stillFailedTests.Count} test(s) failed after retry");
123+
}
100124
}
101125
});
102126

@@ -131,22 +155,34 @@ Task("_NetStandard_Unit_Tests_WithRetry")
131155
var filter = testExecutionHelper.CreateUnitTestFilter(IsRunningOnUnix());
132156
var settings = testExecutionHelper.CreateDotNetTestSettings(resultsPath, filter, framework, configuration);
133157

158+
var initialFailedTests = new List<string>();
134159
try
135160
{
136161
testExecutionHelper.RunDotNetTests(project, settings);
137162
}
138163
catch
139164
{
140165
Warning("Some tests failed. Retrying failed tests...");
166+
initialFailedTests = testRetryHelper.FindFailedDotNetTests(resultsPath);
141167
}
142168

143-
testExecutionHelper.RetryFailedDotNetTests(project, resultsPath, testRetryHelper, framework, configuration);
144-
145-
// Check if any tests still failed after retry
146-
var stillFailedTests = testRetryHelper.FindFailedDotNetTests(resultsPath);
147-
if (stillFailedTests.Any())
169+
if (initialFailedTests.Any())
148170
{
149-
throw new Exception($"{stillFailedTests.Count} test(s) failed after retry");
171+
testExecutionHelper.RetryFailedDotNetTests(project, resultsPath, testRetryHelper, framework, configuration);
172+
173+
// Check retry result files to see if tests still failed
174+
var stillFailedTests = new List<string>();
175+
for (int i = 1; i <= initialFailedTests.Count; i++)
176+
{
177+
var retryResultsPath = paths.TestResults.CombineWithFilePath($"tests-netstandard-unit-{i}.trx");
178+
var retryFailed = testRetryHelper.FindFailedDotNetTests(retryResultsPath);
179+
stillFailedTests.AddRange(retryFailed);
180+
}
181+
182+
if (stillFailedTests.Any())
183+
{
184+
throw new Exception($"{stillFailedTests.Count} test(s) failed after retry");
185+
}
150186
}
151187
});
152188

@@ -177,22 +213,34 @@ Task("_NetStandard_Integration_Tests_WithRetry")
177213
var filter = testExecutionHelper.CreateIntegrationTestFilter();
178214
var settings = testExecutionHelper.CreateDotNetTestSettings(resultsPath, filter, framework, configuration);
179215

216+
var initialFailedTests = new List<string>();
180217
try
181218
{
182219
testExecutionHelper.RunDotNetTests(project, settings);
183220
}
184221
catch
185222
{
186223
Warning("Some tests failed. Retrying failed tests...");
224+
initialFailedTests = testRetryHelper.FindFailedDotNetTests(resultsPath);
187225
}
188226

189-
testExecutionHelper.RetryFailedDotNetTests(project, resultsPath, testRetryHelper, framework, configuration);
190-
191-
// Check if any tests still failed after retry
192-
var stillFailedTests = testRetryHelper.FindFailedDotNetTests(resultsPath);
193-
if (stillFailedTests.Any())
227+
if (initialFailedTests.Any())
194228
{
195-
throw new Exception($"{stillFailedTests.Count} test(s) failed after retry");
229+
testExecutionHelper.RetryFailedDotNetTests(project, resultsPath, testRetryHelper, framework, configuration);
230+
231+
// Check retry result files to see if tests still failed
232+
var stillFailedTests = new List<string>();
233+
for (int i = 1; i <= initialFailedTests.Count; i++)
234+
{
235+
var retryResultsPath = paths.TestResults.CombineWithFilePath($"tests-netstandard-integration-{i}.trx");
236+
var retryFailed = testRetryHelper.FindFailedDotNetTests(retryResultsPath);
237+
stillFailedTests.AddRange(retryFailed);
238+
}
239+
240+
if (stillFailedTests.Any())
241+
{
242+
throw new Exception($"{stillFailedTests.Count} test(s) failed after retry");
243+
}
196244
}
197245
});
198246

src/IO.Ably.Shared/MessageEncoders/MessageHandler.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ internal class MessageHandler
2020

2121
private readonly Protocol _protocol;
2222

23-
private static List<MessageEncoder> AllEncoders { get; } = new List<MessageEncoder>
23+
internal static List<MessageEncoder> AllEncoders { get; } = new List<MessageEncoder>
2424
{
2525
new JsonEncoder(), new Utf8Encoder(), new CipherEncoder(), new VcDiffEncoder(), Base64Encoder,
2626
};
2727

28-
private List<MessageEncoder> Encoders { get; }
28+
internal List<MessageEncoder> Encoders { get; }
2929

3030
private ILogger Logger { get; }
3131

@@ -353,7 +353,7 @@ private Result DecodePayloads(DecodingContext context, IEnumerable<IMessage> pay
353353
var result = Result.Ok();
354354
foreach (var payload in payloads)
355355
{
356-
result = Result.Combine(result, DecodePayload(payload, context, encoders));
356+
result = Result.Combine(result, DecodePayload(payload, context, encoders, Logger));
357357
}
358358

359359
return result;
@@ -476,7 +476,7 @@ public Result DecodeMessages(
476476
foreach (var message in messages ?? Enumerable.Empty<IMessage>())
477477
{
478478
SetMessageIdConnectionIdAndTimestamp(message, index);
479-
var decodeResult = DecodePayload(message, context, Encoders)
479+
var decodeResult = DecodePayload(message, context, Encoders, Logger)
480480
.IfFailure(error => Logger.Warning($"Error decoding message with id: {message.Id}. Error: {error.Message}. Exception: {error.InnerException?.Message}"));
481481

482482
result = Result.Combine(result, decodeResult);

src/IO.Ably.Tests.Shared/Infrastructure/ProtocolDataAttribute.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,15 @@ public ProtocolDataAttribute(params object[] data)
2020
/// <inheritdoc/>
2121
public override IEnumerable<object[]> GetData(MethodInfo testMethod)
2222
{
23+
// Return Protocol.Json with relevant data
2324
var d = new List<object> { Protocol.Json };
2425
d.AddRange(_data);
2526
yield return d.ToArray();
2627

27-
if (Defaults.MsgPackEnabled)
28-
#pragma warning disable 162
29-
{
30-
d = new List<object> { Protocol.MsgPack };
31-
d.AddRange(_data);
32-
yield return d.ToArray();
33-
}
34-
#pragma warning restore 162
28+
// Return Protocol.MsgPack with relevant data
29+
d = new List<object> { Protocol.MsgPack };
30+
d.AddRange(_data);
31+
yield return d.ToArray();
3532
}
3633
}
3734
}

src/IO.Ably.Tests.Shared/MessageEncodes/Base64EncoderTests.cs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,23 +55,7 @@ public void WithMessageAnotherEncoding_LeavesDataAndEncodingIntact()
5555
}
5656
}
5757

58-
public class EncodeWithBinaryProtocol : Base64EncoderTests
59-
{
60-
[Fact]
61-
public void WithBinaryData_LeavesDataAndEncodingIntact()
62-
{
63-
#pragma warning disable 162
64-
IPayload payload = new Message { Data = _binaryData };
65-
66-
payload = _encoder.Encode(payload, new DecodingContext()).Value;
67-
68-
payload.Data.Should().Be(_binaryData);
69-
payload.Encoding.Should().BeNull();
70-
#pragma warning restore 162
71-
}
72-
}
73-
74-
public class EncodeWithTextProtocol : Base64EncoderTests
58+
public class Encode : Base64EncoderTests
7559
{
7660
[Fact]
7761
public void WithBinaryPayloadWithoutPriorEncoding_ConvertsDataToBase64StringAndSetsEncoding()

src/IO.Ably.Tests.Shared/MessageEncodes/MessageEncodersAcceptanceTests.cs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
using System.Threading.Tasks;
55
using FluentAssertions;
66
using IO.Ably.Encryption;
7+
using IO.Ably.MessageEncoders;
78
using IO.Ably.Tests;
89
using Xunit;
910
using Xunit.Abstractions;
1011

11-
#pragma warning disable 162
12-
1312
namespace IO.Ably.AcceptanceTests
1413
{
1514
public class MessageEncodersAcceptanceTests : AblySpecs
@@ -80,6 +79,33 @@ public async Task PublishSupportedMessages(Message message, string encoding)
8079
}
8180
}
8281

82+
[Fact]
83+
public void WithTextProtocolAllEncoderAvailable()
84+
{
85+
// All encoders
86+
var allEncoders = MessageHandler.AllEncoders;
87+
allEncoders.Should().HaveCount(5);
88+
// Encoders available for given MessageHandler
89+
var messageHandler = new MessageHandler(DefaultLogger.LoggerInstance, Protocol.Json);
90+
messageHandler.Encoders.Should().HaveCount(5);
91+
// Available encoders are same as all encoders
92+
Assert.Equal(messageHandler.Encoders, MessageHandler.AllEncoders);
93+
}
94+
95+
[Fact]
96+
public void WithBinaryProtocolAllEncodersExceptBase64Encoder()
97+
{
98+
// All encoders
99+
var allEncoders = MessageHandler.AllEncoders;
100+
allEncoders.Should().HaveCount(5);
101+
// Encoders available for given MessageHandler
102+
var messageHandler = new MessageHandler(DefaultLogger.LoggerInstance, Protocol.MsgPack);
103+
messageHandler.Encoders.Should().HaveCount(4);
104+
105+
messageHandler.Encoders.Should().BeSubsetOf(allEncoders);
106+
messageHandler.Encoders.Should().NotContain(encoder => encoder is Base64Encoder);
107+
}
108+
83109
[Trait("spec", "RSL4d")]
84110
public class WithTextProtocolWithoutEncryption : MockHttpRestSpecs
85111
{

0 commit comments

Comments
 (0)