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

Save and restore random seed #216

Merged
merged 2 commits into from
Aug 7, 2016
Merged

Save and restore random seed #216

merged 2 commits into from
Aug 7, 2016

Conversation

CharliePoole
Copy link
Member

Fixes #97

This fix saves the initial random seed to a file upon discovery and reads it back on execution. Since there is no known writable directory other than the output directory for each assembly, it repeats the action for each assembly. This has the benefit of simplifying the code and also allowing for variation between assemblies in the future.

@@ -123,6 +125,18 @@ public void Load(string settingsXml)
#endif
}

public void SaveRandomSeed(string dirname)
{
using (var writer = new StreamWriter(Path.Combine(dirname, "$RANDOM_SEED$")))
Copy link
Member

Choose a reason for hiding this comment

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

This and the read below should probably be wrapped in a try/catch. Too much can go wrong accessing the filesystem and we don't want to crash the adapter or fail the entire test run. Better to output a log message.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch. I intended to take another look for error handling after coding the happy pathg but didn't... working too fast!

@CharliePoole
Copy link
Member Author

Added try/catch block when reading or writing file that holds the random seed. To allow easier error recovery, we don't try reading or writing the file if the runsettings file has a random seed specified. Should be good to go now.

{
_logger.Error("Failed to save random seed.", ex);
}
finally
Copy link
Member

Choose a reason for hiding this comment

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

A using statement probably would have been cleaner than disposing in a finally block, but good enough.

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 had a using statement but we needed the catch so I made the try explicit. Using inside a try generates two try blocks.

Copy link
Member

Choose a reason for hiding this comment

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

I didn't know that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Unless it's optimized away by the latest compiler... :-)

@CharliePoole CharliePoole merged commit 8a9b8a3 into master Aug 7, 2016
@CharliePoole CharliePoole deleted the issue-97 branch August 7, 2016 22:58
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.

Tests with dynamic/random parameters are never run
2 participants