fix some flakiness around test assets

This commit is contained in:
Krzysztof Wicher 2017-01-19 11:37:34 -08:00
parent 6568113e34
commit 243f92aa47

View file

@ -140,18 +140,16 @@ namespace Microsoft.DotNet.TestFramework
private IEnumerable<FileInfo> LoadInventory(FileInfo file) private IEnumerable<FileInfo> LoadInventory(FileInfo file)
{ {
file.Refresh();
if (!file.Exists) if (!file.Exists)
{ {
return Enumerable.Empty<FileInfo>(); throw new InvalidOperationException("Inventory file should exist.");
} }
var inventory = new List<FileInfo>(); var inventory = new List<FileInfo>();
foreach (var p in File.ReadAllLines(file.FullName))
var lines = file.OpenText();
while (lines.Peek() > 0)
{ {
inventory.Add(new FileInfo(lines.ReadLine())); inventory.Add(new FileInfo(p));
} }
return inventory; return inventory;
@ -159,27 +157,13 @@ namespace Microsoft.DotNet.TestFramework
private void SaveInventory(FileInfo file, IEnumerable<FileInfo> inventory) private void SaveInventory(FileInfo file, IEnumerable<FileInfo> inventory)
{ {
FileUtility.ReplaceWithLock( _dataDirectory.Refresh();
filePath => if (!_dataDirectory.Exists)
{ {
if (!_dataDirectory.Exists) _dataDirectory.Create();
{ }
_dataDirectory.Create();
}
using (var stream = File.WriteAllLines(file.FullName, inventory.Select((fi) => fi.FullName).ToList());
new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None))
{
using (var writer = new StreamWriter(stream))
{
foreach (var path in inventory.Select(i => i.FullName))
{
writer.WriteLine(path);
}
}
}
},
file.FullName);
} }
private IEnumerable<FileInfo> GetFileList() private IEnumerable<FileInfo> GetFileList()
@ -195,15 +179,6 @@ namespace Microsoft.DotNet.TestFramework
Action action) Action action)
{ {
var inventory = Enumerable.Empty<FileInfo>(); var inventory = Enumerable.Empty<FileInfo>();
if (file.Exists)
{
inventory = LoadInventory(file);
}
if(inventory.Any())
{
return inventory;
}
IEnumerable<FileInfo> preInventory; IEnumerable<FileInfo> preInventory;
@ -220,6 +195,7 @@ namespace Microsoft.DotNet.TestFramework
_dataDirectory.FullName, _dataDirectory.FullName,
lockedToken => lockedToken =>
{ {
file.Refresh();
if (file.Exists) if (file.Exists)
{ {
inventory = LoadInventory(file); inventory = LoadInventory(file);