// Wait (up to three seconds) for data uploaded to become available. // Currently only used in unit testing. // I have no idea whether 3s is an adequate time to wait for 'eventual consistency'. So far it seems to work. internal void WaitUntilS3DataIsOnServer(string bookPath) { var s3Id = S3BookId(BookMetaData.FromFolder(bookPath)); var count = Directory.GetFiles(bookPath).Length; for (int i = 0; i < 30; i++) { var uploaded = _s3Client.GetBookFileCount(s3Id); if (uploaded >= count) { return; } Thread.Sleep(100); } throw new ApplicationException("S3 is very slow today"); }
// Wait (up to three seconds) for data uploaded to become available. // Currently only used in unit testing. // I have no idea whether 3s is an adequate time to wait for 'eventual consistency'. So far it seems to work. internal void WaitUntilS3DataIsOnServer(string bucket, string bookPath) { var s3Id = S3BookId(BookMetaData.FromFolder(bookPath)); // There's a few files we don't upload, but meta.bak is the only one that regularly messes up the count. // Some tests also deliberately include a _broken_ file to check they aren't uploaded, // so we'd better not wait for that to be there, either. var count = Directory.GetFiles(bookPath).Count(p => !p.EndsWith(".bak") && !p.Contains(BookStorage.PrefixForCorruptHtmFiles)); for (int i = 0; i < 30; i++) { var uploaded = _s3Client.GetBookFileCount(bucket, s3Id); if (uploaded >= count) { return; } Thread.Sleep(100); } throw new ApplicationException("S3 is very slow today"); }