Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mrica-equinor committed Jul 17, 2024
1 parent 82c96ec commit d56f8e9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
13 changes: 11 additions & 2 deletions backend/api.test/Database/DatabaseUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public async Task<MissionRun> NewMissionRun(
bool writeToDatabase = false,
MissionRunType missionRunType = MissionRunType.Normal,
MissionStatus missionStatus = MissionStatus.Pending,
string? isarMissionId = null
string? isarMissionId = null,
Api.Database.Models.TaskStatus taskStatus = Api.Database.Models.TaskStatus.Successful
)
{
var missionRun = new MissionRun
Expand All @@ -65,14 +66,22 @@ public async Task<MissionRun> NewMissionRun(
{
new(new Pose(), MissionTaskType.Localization)
};
missionRun.Tasks[0].Status = taskStatus;
}
if (missionRunType == MissionRunType.ReturnHome)
else if (missionRunType == MissionRunType.ReturnHome)
{
missionRun.Tasks = new List<MissionTask>
{
new(new Pose(), MissionTaskType.ReturnHome)
};
}
else
{
missionRun.Tasks = new List<MissionTask>
{
new(new Pose(), MissionTaskType.Inspection)
};
}
if (writeToDatabase)
{
return await _missionRunService.Create(missionRun, false);
Expand Down
8 changes: 4 additions & 4 deletions backend/api.test/EventHandlers/TestMissionEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public async void QueuedMissionsAreAbortedWhenLocalizationFails()
var deck = await _databaseUtilities.NewDeck(installation.InstallationCode, plant.PlantCode);
var area = await _databaseUtilities.NewArea(installation.InstallationCode, plant.PlantCode, deck.Name);
var robot = await _databaseUtilities.NewRobot(RobotStatus.Available, installation, area);
var localizationMissionRun = await _databaseUtilities.NewMissionRun(installation.InstallationCode, robot, area, true, MissionRunType.Localization, MissionStatus.Ongoing, Guid.NewGuid().ToString());
var localizationMissionRun = await _databaseUtilities.NewMissionRun(installation.InstallationCode, robot, area, true, MissionRunType.Localization, MissionStatus.Ongoing, Guid.NewGuid().ToString(), TaskStatus.Failed);
var missionRun1 = await _databaseUtilities.NewMissionRun(installation.InstallationCode, robot, area, true);

Thread.Sleep(100);
Expand All @@ -311,7 +311,7 @@ public async void QueuedMissionsAreAbortedWhenLocalizationFails()
RobotName = robot.Name,
IsarId = robot.IsarId,
MissionId = localizationMissionRun.IsarMissionId,
Status = "failed",
Status = "successful",
Timestamp = DateTime.UtcNow
});

Expand Down Expand Up @@ -376,7 +376,7 @@ public async void QueuedContinuesWhenOnIsarStatusHappensAtTheSameTimeAsOnIsarMis
var deck = await _databaseUtilities.NewDeck(installation.InstallationCode, plant.PlantCode);
var area = await _databaseUtilities.NewArea(installation.InstallationCode, plant.PlantCode, deck.Name);
var robot = await _databaseUtilities.NewRobot(RobotStatus.Available, installation, null);
var missionRun1 = await _databaseUtilities.NewMissionRun(installation.InstallationCode, robot, area, true);
var missionRun1 = await _databaseUtilities.NewMissionRun(installation.InstallationCode, robot, area, true, MissionRunType.Localization, MissionStatus.Ongoing, Guid.NewGuid().ToString());
var missionRun2 = await _databaseUtilities.NewMissionRun(installation.InstallationCode, robot, area, true);
Thread.Sleep(100);

Expand Down Expand Up @@ -411,7 +411,7 @@ public async void QueuedContinuesWhenOnIsarStatusHappensAtTheSameTimeAsOnIsarMis
// Assert
var postTestMissionRun1 = await _missionRunService.ReadById(missionRun1.Id);
Assert.Equal(MissionRunType.Localization, postTestMissionRun1!.MissionRunType);
Assert.Equal(MissionStatus.Successful, postTestMissionRun1!.Status);
Assert.Equal(TaskStatus.Successful, postTestMissionRun1!.Tasks[0].Status);
var postTestMissionRun2 = await _missionRunService.ReadById(missionRun2.Id);
Assert.Equal(MissionStatus.Ongoing, postTestMissionRun2!.Status);
}
Expand Down
10 changes: 9 additions & 1 deletion backend/api/Database/Models/MissionTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,16 @@ public MissionTask(Pose robotPose, MissionTaskType type)
Status = TaskStatus.NotStarted;
Inspections = new List<Inspection>();
break;
case MissionTaskType.Inspection:
Type = type;
Description = "Inspection";
RobotPose = robotPose;
TaskOrder = 0;
Status = TaskStatus.NotStarted;
Inspections = new List<Inspection>();
break;
default:
throw new MissionTaskNotFoundException("MissionTaskType should be Localization or ReturnHome");
throw new MissionTaskNotFoundException("MissionTaskType should be Localization, ReturnHome or Inspection");
}
}

Expand Down

0 comments on commit d56f8e9

Please sign in to comment.