Skip to content

Commit 3d8b8b8

Browse files
committed
Test running missions when one is in wrong area
1 parent 21766aa commit 3d8b8b8

File tree

4 files changed

+73
-4
lines changed

4 files changed

+73
-4
lines changed

backend/api.test/Database/DatabaseUtilities.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,11 @@ public async Task<MissionRun> NewMissionRun(
9595
MissionRunType missionRunType = MissionRunType.Normal,
9696
MissionStatus missionStatus = MissionStatus.Pending,
9797
string isarMissionId = "",
98-
Api.Database.Models.TaskStatus taskStatus = Api.Database.Models.TaskStatus.Successful
98+
MissionTask[] tasks = null!
9999
)
100100
{
101+
tasks ??= [];
102+
101103
if (string.IsNullOrEmpty(isarMissionId))
102104
isarMissionId = Guid.NewGuid().ToString();
103105
var missionRun = new MissionRun
@@ -110,7 +112,7 @@ public async Task<MissionRun> NewMissionRun(
110112
Status = missionStatus,
111113
DesiredStartTime = DateTime.UtcNow,
112114
InspectionArea = inspectionArea,
113-
Tasks = [],
115+
Tasks = tasks,
114116
InstallationCode = installationCode,
115117
};
116118

backend/api.test/Services/MissionSchedulingService.cs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Api.Controllers.Models;
33
using Api.Database.Models;
44
using Api.Services;
5+
using Api.Services.Models;
56
using Api.Test.Database;
67
using Microsoft.Extensions.DependencyInjection;
78
using Testcontainers.PostgreSql;
@@ -72,5 +73,58 @@ await DatabaseUtilities.NewMissionRun(
7273
// We expect two new missions since a return home mission will also be scheduled
7374
Assert.Equal(nReportsBefore + 1, nReportsAfter);
7475
}
76+
77+
[Fact]
78+
public async Task CheckThatReturnHomeIsNotDeletedWhenPreviousMissionWasOutsideInspectionArea()
79+
{
80+
// Arrange
81+
var installation = await DatabaseUtilities.NewInstallation();
82+
var plant = await DatabaseUtilities.NewPlant(installation.InstallationCode);
83+
var inspectionArea1 = await DatabaseUtilities.NewInspectionArea(
84+
installation.InstallationCode,
85+
plant.PlantCode,
86+
inspectionAreaName: "Inspection area 1",
87+
new InspectionAreaPolygon
88+
{
89+
ZMin = 0,
90+
ZMax = 10,
91+
Positions = [new XYPosition(x: 0, y: 0), new XYPosition(x: 0, y: 10), new XYPosition(x: 10, y: 10), new XYPosition(x: 10, y: 0)]
92+
}
93+
);
94+
var inspectionArea2 = await DatabaseUtilities.NewInspectionArea(
95+
installation.InstallationCode,
96+
plant.PlantCode,
97+
inspectionAreaName: "Inspection area 2",
98+
new InspectionAreaPolygon
99+
{
100+
ZMin = 0,
101+
ZMax = 10,
102+
Positions = [new XYPosition(x: 0, y: 0), new XYPosition(x: 0, y: -10), new XYPosition(x: -10, y: -10), new XYPosition(x: -10, y: 0)]
103+
}
104+
);
105+
106+
var taskOutsideInspectionArea = new MissionTask(new Pose(-5, -5, 0, 0, 0, 0, 0), MissionTaskType.Inspection);
107+
108+
var robot = await DatabaseUtilities.NewRobot(RobotStatus.Available, installation, inspectionArea2);
109+
await DatabaseUtilities.NewMissionRun(
110+
installation.InstallationCode,
111+
robot,
112+
inspectionArea1,
113+
writeToDatabase: true,
114+
tasks: [taskOutsideInspectionArea]
115+
);
116+
117+
// Act
118+
await MissionSchedulingService.StartNextMissionRunIfSystemIsAvailable(robot);
119+
120+
// Assert
121+
var reportsAfter = await MissionRunService.ReadAll(
122+
new MissionRunQueryStringParameters()
123+
);
124+
125+
Assert.Single(reportsAfter);
126+
Assert.True(reportsAfter[0].IsReturnHomeMission());
127+
Assert.Equal(MissionStatus.Ongoing, reportsAfter[0].Status);
128+
}
75129
}
76130
}

backend/api/Services/Models/InspectionAreaPolygon.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@ public class InspectionAreaPolygon
1616

1717
public class XYPosition
1818
{
19+
public XYPosition()
20+
{
21+
22+
}
23+
24+
public XYPosition(float x = 0, float y = 0)
25+
{
26+
X = x;
27+
Y = y;
28+
}
29+
1930
[JsonPropertyName("x")]
2031
public double X { get; set; }
2132

backend/api/Utilities/Exceptions.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,16 @@ public class RobotNotAvailableException(string message) : Exception(message) { }
5757
public class RobotBusyException(string message) : Exception(message) { }
5858

5959
public class RobotNotInSameInstallationAsMissionException(string message)
60-
: Exception(message) { }
60+
: Exception(message)
61+
{ }
6162

6263
public class PoseNotFoundException(string message) : Exception(message) { }
6364

6465
public class IsarCommunicationException(string message) : Exception(message) { }
6566

6667
public class ReturnToHomeMissionFailedToScheduleException(string message)
67-
: Exception(message) { }
68+
: Exception(message)
69+
{ }
6870

6971
public class RobotCurrentAreaMissingException(string message) : Exception(message) { }
7072

0 commit comments

Comments
 (0)