From 9d016d6b13abc01843d9f8d01cb39278a7a47a88 Mon Sep 17 00:00:00 2001 From: Alexey <248997@gmail.com> Date: Thu, 26 Dec 2024 18:25:02 +0500 Subject: [PATCH] fix(test): UploadAndStartMission_StrictSequenceExecuting On some slow platforms, start the mission before busy flag is released. --- .../Commands/CommandIntComplexTest.cs | 12 +++--------- .../Missions/MissionExComplexTest.cs | 16 +++++++++++++++- .../Missions/Client/Ex/MissionClientEx.cs | 1 + .../Missions/Server/Ex/IMissionServerEx.cs | 1 - .../Missions/Server/Ex/MissionServerEx.cs | 5 +---- 5 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/Asv.Mavlink.Test/Microservices/Commands/CommandIntComplexTest.cs b/src/Asv.Mavlink.Test/Microservices/Commands/CommandIntComplexTest.cs index 06ceeccc..d0213638 100644 --- a/src/Asv.Mavlink.Test/Microservices/Commands/CommandIntComplexTest.cs +++ b/src/Asv.Mavlink.Test/Microservices/Commands/CommandIntComplexTest.cs @@ -627,12 +627,9 @@ public async Task SendCommandInt_DifferentMavResults_Success(MavResult mavResult { called++; _taskCompletionSource.TrySetResult(args); + packetFromClient = args; return Task.FromResult(CommandResult.FromResult(mavResult)); }; - using var sub = Link.Client.OnTxMessage.Subscribe(p => - { - packetFromClient = p as CommandIntPacket; - }); // Act await _client.SendCommandInt( @@ -785,13 +782,10 @@ public async Task CommandInt_WithCustomConfig_Success(int maxCommandAttempts, in called++; var result = MavResult.MavResultAccepted; _taskCompletionSource.TrySetResult(args); + packetFromClient = args; return Task.FromResult(CommandResult.FromResult(result)); }; - using var sub = Link.Client.OnTxMessage.Subscribe(p => - { - packetFromClient = p as CommandIntPacket; - }); - + // Act var result = await client.CommandInt( MavCmd.MavCmdUser1, diff --git a/src/Asv.Mavlink.Test/Microservices/Missions/MissionExComplexTest.cs b/src/Asv.Mavlink.Test/Microservices/Missions/MissionExComplexTest.cs index 55ecd60d..2c2685c1 100644 --- a/src/Asv.Mavlink.Test/Microservices/Missions/MissionExComplexTest.cs +++ b/src/Asv.Mavlink.Test/Microservices/Missions/MissionExComplexTest.cs @@ -550,7 +550,21 @@ public async Task UploadAndStartMission_StrictSequenceExecuting_Success(ushort s }); // Act - _server.StartMission(skip); + + // On some slow platforms, start the mission before the upload is complete. + // We attempt to start it multiple times. It's impossible in real life with async communication + start: + try + { + _server.StartMission(skip); + } + catch (MavlinkException e) + { + Log.WriteLine("====> tests is slow. Trying to start mission multiple times <==="); + await Task.Delay(10); + goto start; + } + await tcs.Task; // Assert diff --git a/src/Asv.Mavlink/Microservices/Missions/Client/Ex/MissionClientEx.cs b/src/Asv.Mavlink/Microservices/Missions/Client/Ex/MissionClientEx.cs index 8fecc6d2..2aa49372 100644 --- a/src/Asv.Mavlink/Microservices/Missions/Client/Ex/MissionClientEx.cs +++ b/src/Asv.Mavlink/Microservices/Missions/Client/Ex/MissionClientEx.cs @@ -156,6 +156,7 @@ public async Task Upload(CancellationToken cancel, Action? progress = nu await _client.MissionSetCount((ushort) _missionSource.Count, cancel).ConfigureAwait(false); await tcs.Task.ConfigureAwait(false); + progress?.Invoke(1); _isMissionSynced.OnNext(true); } diff --git a/src/Asv.Mavlink/Microservices/Missions/Server/Ex/IMissionServerEx.cs b/src/Asv.Mavlink/Microservices/Missions/Server/Ex/IMissionServerEx.cs index b65fd3ae..a5390126 100644 --- a/src/Asv.Mavlink/Microservices/Missions/Server/Ex/IMissionServerEx.cs +++ b/src/Asv.Mavlink/Microservices/Missions/Server/Ex/IMissionServerEx.cs @@ -19,7 +19,6 @@ public enum MissionServerState public interface IMissionServerEx : IMavlinkMicroserviceServer { - IMissionServer Base { get; } ReadOnlyReactiveProperty Current { get; } ReadOnlyReactiveProperty Reached { get; } diff --git a/src/Asv.Mavlink/Microservices/Missions/Server/Ex/MissionServerEx.cs b/src/Asv.Mavlink/Microservices/Missions/Server/Ex/MissionServerEx.cs index dcdaedfc..eea2fcd5 100644 --- a/src/Asv.Mavlink/Microservices/Missions/Server/Ex/MissionServerEx.cs +++ b/src/Asv.Mavlink/Microservices/Missions/Server/Ex/MissionServerEx.cs @@ -19,10 +19,7 @@ public sealed class MissionServerEx : MavlinkMicroserviceServer, IMissionServerE private const int InternalBusyStateClearAll = 1; private const int InternalBusyStateUploadMission = 2; private const int InternalBusyStateStartMission = 3; - - - private int _internalBusyState; - + private int _internalBusyState = InternalBusyStateIdle; private readonly IStatusTextServer _statusLogger; private readonly ILogger _logger;