Fix race in dotnet-watch test (#9649)
This commit is contained in:
parent
8eb2e8baec
commit
c69395afbd
|
|
@ -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))
|
||||||
|
|
|
||||||
|
|
@ -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();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue