Fix race in dotnet-watch test (#9649)

This commit is contained in:
BrennanConroy 2019-04-24 12:57:58 -07:00 committed by GitHub
parent 8eb2e8baec
commit c69395afbd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 4 deletions

View File

@ -93,10 +93,8 @@ namespace Microsoft.DotNet.Watcher
if (finishedTask == processTask) if (finishedTask == processTask)
{ {
_reporter.Warn("Waiting for a file to change before restarting dotnet...");
// Now wait for a file to change before restarting process // Now wait for a file to change before restarting process
await fileSetWatcher.GetChangedFileAsync(cancellationToken); await fileSetWatcher.GetChangedFileAsync(cancellationToken, () => _reporter.Warn("Waiting for a file to change before restarting dotnet..."));
} }
if (!string.IsNullOrEmpty(fileSetTask.Result)) if (!string.IsNullOrEmpty(fileSetTask.Result))

View File

@ -22,7 +22,7 @@ namespace Microsoft.DotNet.Watcher.Internal
_fileWatcher = new FileWatcher(reporter); _fileWatcher = new FileWatcher(reporter);
} }
public async Task<string> GetChangedFileAsync(CancellationToken cancellationToken) public async Task<string> GetChangedFileAsync(CancellationToken cancellationToken, Action startedWatching)
{ {
foreach (var file in _fileSet) foreach (var file in _fileSet)
{ {
@ -41,12 +41,19 @@ namespace Microsoft.DotNet.Watcher.Internal
}; };
_fileWatcher.OnFileChange += callback; _fileWatcher.OnFileChange += callback;
startedWatching();
var changedFile = await tcs.Task; var changedFile = await tcs.Task;
_fileWatcher.OnFileChange -= callback; _fileWatcher.OnFileChange -= callback;
return changedFile; return changedFile;
} }
public Task<string> GetChangedFileAsync(CancellationToken cancellationToken)
{
return GetChangedFileAsync(cancellationToken, () => {});
}
public void Dispose() public void Dispose()
{ {
_fileWatcher.Dispose(); _fileWatcher.Dispose();