Skip to content

Commit

Permalink
mazak: fix a bug when downloading a new program
Browse files Browse the repository at this point in the history
  • Loading branch information
wuzzeb committed Sep 9, 2024
1 parent 858f4e0 commit 4b50e5e
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
30 changes: 30 additions & 0 deletions server/machines/mazak/sync/MazakSync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,36 @@ public IEnumerable<string> CheckNewJobs(IRepository db, NewJobs jobs)
{
ProgramRevision lookupProg(string prog, long? rev)
{
// while checking jobs, a newly downloaded program might not yet
// be in the database. Therefore, we need to check if the program
// is going to be included as part of the download
NewProgramContent? newlyAdded = jobs.Programs?.FirstOrDefault(p =>
{
if (rev.HasValue && rev.Value != 0)
{
return p.ProgramName == prog && p.Revision == rev.Value;
}
else
{
// 0 revision just means most recent
return p.ProgramName == prog;
}
});

if (newlyAdded != null)
{
return new ProgramRevision()
{
ProgramName = prog,
Comment = newlyAdded.Comment,
CellControllerProgramName = "", // not yet in the cell controller
// This revision isn't correct since a 0 or negative revision will be
// assigned as part of the transaction adding the jobs and programs
// to the database.
Revision = newlyAdded.Revision,
};
}

if (rev.HasValue)
{
return db.LoadProgram(prog, rev.Value);
Expand Down
48 changes: 48 additions & 0 deletions server/test/mazak/SyncSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,54 @@ public void CheckFailMissingProgram()
);
}

[Fact]
public void CheckSucceedIfProgramInDownload()
{
var jsonSettings = new JsonSerializerOptions();
FMSInsightWebHost.JsonSettings(jsonSettings);
_read
.LoadAllData()
.Returns(
new MazakAllData()
{
MainPrograms =
[
new MazakProgramRow() { MainProgram = "1001", Comment = "" },
// no 1002
new MazakProgramRow() { MainProgram = "1003", Comment = "" },
new MazakProgramRow() { MainProgram = "1004", Comment = "" },
],
Fixtures = [],
Pallets = [],
Parts = [],
Schedules = [],
}
);

var newJ = JsonSerializer.Deserialize<NewJobs>(
File.ReadAllText(Path.Combine("..", "..", "..", "sample-newjobs", "fixtures-queues.json")),
jsonSettings
);

newJ = newJ with
{
Programs =
[
new NewProgramContent()
{
ProgramName = "1002",
Comment = "program 1002",
ProgramContent = "content for 1002",
Revision = -1,
},
],
};

using var db = repo.OpenConnection();

_sync.CheckNewJobs(db, newJ).Should().BeEmpty();
}

[Fact]
public void MissingQueue()
{
Expand Down

0 comments on commit 4b50e5e

Please sign in to comment.