Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #1672 Errors are not propagated on failed simulation run #1709

Merged
merged 4 commits into from
Sep 28, 2022

Conversation

rwmcintosh
Copy link
Member

No description provided.

var simulationRunResults = _simModelBatch.RunSimulation();

if (!simulationRunResults.Success)
throw new OSPSuiteException(simulationRunResults.Error);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsuccessful run must be signaled by exception

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep

var hasResults = simulationHasResults(_simModelSimulation);

return new SimulationRunResults(success: hasResults, warnings: WarningsFrom(_simModelSimulation), results: getResults(),
error: hasResults ? null : Error.SimulationDidNotProduceResults);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why don't you create a method (something around the lines of...)

createSimulationResults(string errorFromException = null) {
var hasResults = simulationHasResults(_simModelSimulation);
var warnings = WarningsFrom(_simModelSimulation);
var error = errorFromException ??  (hasResults ? null : Error.SimulationDidNotProduceResults)
if(error==null){
return SimulationRunResults(success: true , warnings, results: getResults())
}

//error
return SimulationRunResults(false, warnings, error)
}

and call that in both instances?

var id = _ids.First();
var simulationBatch = Api.GetSimulationBatchFactory().Create(_simulation, _concurrentRunSimulationBatch.SimulationBatchOptions);

The.Action(() => simulationBatch.Run(_simulationBatchRunValues.FirstOrDefault(v => v.Id == id)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hum I don't get it. The action was called already in RunConcurrently
So i think this test should check that _results has en entry with success=false and an error

That tests here is a test for the _simulationBatch or sthg. No?

Copy link
Member

@msevestre msevestre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering if we can have the implementation only once for the returning of the results
Also the tests is not what I would except. I feel you are testing something else (this test is valid but for another sut)

}

private bool simulationHasResults(Simulation simModelSimulation)
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: This is ok to use the short hand syntax (see below)

private bool simulationHasResults(Simulation simModelSimulation) => simModelSimulation.AllValues.Any();

var warnings = WarningsFrom(_simModelSimulation);
var error = errorFromException ?? (hasResults ? null : Error.SimulationDidNotProduceResults);
if (error == null)
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI Also. Not required when a single return
if(error ==null)
return xxx

[Observation]
public void should_return_a_result_with_success_set_to_false()
{
_results.All(x => x.Succeeded).ShouldBeFalse();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a test that now verifies that this flag is sometimes true? (e.g. can you set the parameter for one run instead as for all). Then one run should be success and the one where it fails should be false.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do now.

@msevestre msevestre merged commit 177e79c into develop Sep 28, 2022
@msevestre msevestre deleted the 1672-errors-are-not-propagated branch September 28, 2022 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants