-
Notifications
You must be signed in to change notification settings - Fork 106
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
Conversation
@@ -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$"))) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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... :-)
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.