Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pwiz_tools/Skyline/TestUtil/AsSmallMoleculeTestUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,13 @@ public static SrmDocument ConvertToSmallMolecules(SrmDocument doc, ref string do
{
docContainer.SetDocument(docLoad, null, true);
docContainer.AssertComplete();
// ConvertToSmallMolecules skips library conversion entirely unless
// Libraries.IsLoaded, so the conversion under test depends on winning a
// race with the library loader. Whichever conversion test ran first in a
// process lost it: no converted .blib was written, the converted document
// had no library dot product where the original did, and the comparison
// below failed. Later tests in the same process passed on a warm cache.
docContainer.WaitForLibrariesLoaded();
doc = docContainer.Document;
}
}
Expand Down Expand Up @@ -280,6 +287,7 @@ public static SrmDocument ConvertToSmallMolecules(SrmDocument doc, ref string do
{
docContainer.SetDocument(docResults, null, true);
docContainer.AssertComplete();
docContainer.WaitForLibrariesLoaded();
doc = docContainer.Document;
}
AssertEx.ConvertedSmallMoleculeDocumentIsSimilar(docOriginal, doc, Path.GetDirectoryName(docPath), mode);
Expand Down
29 changes: 29 additions & 0 deletions pwiz_tools/Skyline/TestUtil/ResultsUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ public ResultsTestDocumentContainer(SrmDocument docInitial, string pathInitial,

private const int SLEEP_INTERVAL = 10;
public const int WAIT_TIME = 5 * 1000; // 5 seconds
public const int WAIT_TIME_LIBRARIES = 60 * 1000; // 60 seconds

private static int GetWaitCycles(int millis = WAIT_TIME)
{
Expand All @@ -277,6 +278,34 @@ public bool AnyProcessing
get { return BackgroundLoaders.Any(l => l.AnyProcessing()); }
}

/// <summary>
/// Waits for the document's spectral libraries to finish loading.
/// <see cref="AssertComplete"/> only inspects the chromatogram loader's progress, so it
/// can return while the library manager is still working. A caller that then reads
/// Settings.PeptideSettings.Libraries.IsLoaded sees false purely because it got there
/// first, and silently takes whatever path the code has for a library-less document.
/// A document with no libraries reports itself loaded, so this returns immediately.
/// </summary>
public void WaitForLibrariesLoaded(int millis = WAIT_TIME_LIBRARIES)
{
int waitCycles = GetWaitCycles(millis);
for (int i = 0; i < waitCycles; i++)
{
if (Document.Settings.PeptideSettings.Libraries.IsLoaded)
return;
Thread.Sleep(SLEEP_INTERVAL);
}
// One last look: the loop sleeps after its final check, so the libraries may have
// finished during that sleep, and a timeout below SLEEP_INTERVAL yields no cycles
// at all and must still get one check rather than failing without ever looking.
if (Document.Settings.PeptideSettings.Libraries.IsLoaded)
return;

Assert.Fail("Libraries still not loaded after {0} seconds: {1}",
waitCycles*SLEEP_INTERVAL/1000,
Document.Settings.PeptideSettings.Libraries.IsNotLoadedExplained);
}

public void AssertComplete()
{
if (LastProgress == null || LastProgress.IsComplete) return;
Expand Down