mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-12-05 08:44:36 +00:00
Improved the pauses between indexing steps and between files of the Batch Processing Assistant (#1240)
This commit is contained in:
1 parent
a117074972
commit
899139c88b
32 files changed
+787
-425
No files matched your search
@@ -1,72 +0,0 @@
|
||||
using AIStudio.Settings.DataModel;
|
||||
using AIStudio.Tools.Services.Indexing;
|
||||
|
||||
namespace AIStudio.Tests.Tools;
|
||||
|
||||
/// <summary>
|
||||
/// Checks which bounds of the pause between two indexing steps apply, as the user set them and as configuration plugins lock them.
|
||||
/// </summary>
|
||||
[TestFixture]
|
||||
public sealed class PauseRangeTests
|
||||
{
|
||||
[Test]
|
||||
public void BoundsInOrderStayAsTheyAre()
|
||||
{
|
||||
Assert.That(PauseRange.GetEffective(10, false, 20, false), Is.EqualTo(new PauseRange(10, 20)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AnUpperBoundBelowTheLowerOneIsRaisedToIt()
|
||||
{
|
||||
Assert.That(PauseRange.GetEffective(60, false, 20, false), Is.EqualTo(new PauseRange(60, 60)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ALockedLowerBoundRaisesTheUpperOne()
|
||||
{
|
||||
Assert.That(PauseRange.GetEffective(60, true, 20, false), Is.EqualTo(new PauseRange(60, 60)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ALockedUpperBoundLowersTheLowerOne()
|
||||
{
|
||||
Assert.That(PauseRange.GetEffective(60, false, 20, true), Is.EqualTo(new PauseRange(20, 20)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BothBoundsLockedTheWrongWayRoundLetTheLongerPauseWin()
|
||||
{
|
||||
Assert.That(PauseRange.GetEffective(60, true, 20, true), Is.EqualTo(new PauseRange(60, 60)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BoundsOutsideTheAllowedRangeAreClamped()
|
||||
{
|
||||
Assert.That(PauseRange.GetEffective(-5, false, 1_000, false), Is.EqualTo(new PauseRange(0, DataDataSourceIndexing.MAX_PAUSE_BETWEEN_STEPS_SECONDS)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BoundsInOrderComeFromTheSettingsWithoutAskingForLocks()
|
||||
{
|
||||
var settings = new DataDataSourceIndexing
|
||||
{
|
||||
MinimumPauseBetweenStepsSeconds = 10,
|
||||
MaximumPauseBetweenStepsSeconds = 20
|
||||
};
|
||||
|
||||
Assert.That(PauseRange.FromSettings(settings), Is.EqualTo(new PauseRange(10, 20)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void OnlyZeroForBothBoundsMeansNoPause()
|
||||
{
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(PauseRange.GetEffective(0, false, 0, false).IsNone, Is.True);
|
||||
Assert.That(PauseRange.GetEffective(0, false, 5, false).IsNone, Is.False);
|
||||
Assert.That(PauseRange.GetEffective(30, false, 0, false), Is.EqualTo(new PauseRange(30, 30)));
|
||||
Assert.That(new DataDataSourceIndexing().MinimumPauseBetweenStepsSeconds, Is.Zero);
|
||||
Assert.That(new DataDataSourceIndexing().MaximumPauseBetweenStepsSeconds, Is.Zero);
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
using AIStudio.Tools.Services.Indexing;
|
||||
using AIStudio.Tools.Pauses;
|
||||
|
||||
namespace AIStudio.Tests.Tools;
|
||||
namespace AIStudio.Tests.Tools.Pauses;
|
||||
|
||||
/// <summary>
|
||||
/// Checks the pause between two indexing steps, which spares an embedding server that many people share.
|
||||
@@ -0,0 +1,147 @@
|
||||
using AIStudio.Settings.DataModel;
|
||||
using AIStudio.Tools.Pauses;
|
||||
|
||||
namespace AIStudio.Tests.Tools.Pauses;
|
||||
|
||||
/// <summary>
|
||||
/// Checks which bounds of a random pause apply, as the user set them, as configuration plugins lock them, and within the limits of each feature.
|
||||
/// </summary>
|
||||
[TestFixture]
|
||||
public sealed class PauseRangeTests
|
||||
{
|
||||
private static readonly Func<bool> LOCKED = () => true;
|
||||
|
||||
private static readonly Func<bool> UNLOCKED = () => false;
|
||||
|
||||
private static readonly PauseLimits INDEXING = DataDataSourceIndexing.PAUSE_LIMITS;
|
||||
|
||||
private static readonly PauseLimits BATCH_PROCESSING = DataBatchProcessing.PAUSE_LIMITS;
|
||||
|
||||
[Test]
|
||||
public void BoundsInOrderStayAsTheyAre()
|
||||
{
|
||||
Assert.That(PauseRange.GetEffective(INDEXING, 10, UNLOCKED, 20, UNLOCKED), Is.EqualTo(new PauseRange(10, 20)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AnUpperBoundBelowTheLowerOneIsRaisedToIt()
|
||||
{
|
||||
Assert.That(PauseRange.GetEffective(INDEXING, 60, UNLOCKED, 20, UNLOCKED), Is.EqualTo(new PauseRange(60, 60)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ALockedLowerBoundRaisesTheUpperOne()
|
||||
{
|
||||
Assert.That(PauseRange.GetEffective(INDEXING, 60, LOCKED, 20, UNLOCKED), Is.EqualTo(new PauseRange(60, 60)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ALockedUpperBoundLowersTheLowerOne()
|
||||
{
|
||||
Assert.That(PauseRange.GetEffective(INDEXING, 60, UNLOCKED, 20, LOCKED), Is.EqualTo(new PauseRange(20, 20)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BothBoundsLockedTheWrongWayRoundLetTheLongerPauseWin()
|
||||
{
|
||||
Assert.That(PauseRange.GetEffective(INDEXING, 60, LOCKED, 20, LOCKED), Is.EqualTo(new PauseRange(60, 60)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BoundsOutsideTheLimitsAreClamped()
|
||||
{
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(PauseRange.GetEffective(INDEXING, -5, UNLOCKED, 1_000, UNLOCKED), Is.EqualTo(new PauseRange(0, 300)));
|
||||
Assert.That(PauseRange.GetEffective(BATCH_PROCESSING, -5, UNLOCKED, 1_000, UNLOCKED), Is.EqualTo(new PauseRange(6, 300)));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BoundsBelowTheShortestPauseOfAFeatureAreRaisedToIt()
|
||||
{
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(PauseRange.GetEffective(BATCH_PROCESSING, 0, UNLOCKED, 3, UNLOCKED), Is.EqualTo(new PauseRange(6, 6)));
|
||||
Assert.That(PauseRange.GetEffective(BATCH_PROCESSING, 2, UNLOCKED, 20, UNLOCKED), Is.EqualTo(new PauseRange(6, 20)));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ALockedUpperBoundLowersTheLowerOneOnlyToTheShortestPauseOfAFeature()
|
||||
{
|
||||
Assert.That(PauseRange.GetEffective(BATCH_PROCESSING, 60, UNLOCKED, 2, LOCKED), Is.EqualTo(new PauseRange(6, 6)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheLocksAreAskedOnlyWhileTheBoundsAreTheWrongWayRound()
|
||||
{
|
||||
var asked = 0;
|
||||
var countingLock = () =>
|
||||
{
|
||||
asked++;
|
||||
return false;
|
||||
};
|
||||
|
||||
PauseRange.GetEffective(INDEXING, 10, countingLock, 10, countingLock);
|
||||
PauseRange.GetEffective(INDEXING, 10, countingLock, 20, countingLock);
|
||||
PauseRange.GetEffective(BATCH_PROCESSING, 0, countingLock, 3, countingLock);
|
||||
Assert.That(asked, Is.Zero);
|
||||
|
||||
PauseRange.GetEffective(INDEXING, 20, countingLock, 10, countingLock);
|
||||
Assert.That(asked, Is.Positive);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheIndexingTakesItsBoundsFromItsSettings()
|
||||
{
|
||||
var settings = new DataDataSourceIndexing
|
||||
{
|
||||
MinimumPauseBetweenStepsSeconds = 10,
|
||||
MaximumPauseBetweenStepsSeconds = 20
|
||||
};
|
||||
|
||||
Assert.That(settings.EffectivePauseRange, Is.EqualTo(new PauseRange(10, 20)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheBatchProcessingPausesSixToTenSecondsByDefault()
|
||||
{
|
||||
var settings = new DataBatchProcessing();
|
||||
Assert.That(PauseRange.GetEffective(BATCH_PROCESSING, settings.MinimumDelaySeconds, UNLOCKED, settings.MaximumDelaySeconds, UNLOCKED), Is.EqualTo(new PauseRange(6, 10)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void OnlyZeroForBothBoundsMeansNoPause()
|
||||
{
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(PauseRange.GetEffective(INDEXING, 0, UNLOCKED, 0, UNLOCKED).IsNone, Is.True);
|
||||
Assert.That(PauseRange.GetEffective(INDEXING, 0, UNLOCKED, 5, UNLOCKED).IsNone, Is.False);
|
||||
Assert.That(PauseRange.GetEffective(INDEXING, 30, UNLOCKED, 0, UNLOCKED), Is.EqualTo(new PauseRange(30, 30)));
|
||||
Assert.That(new DataDataSourceIndexing().EffectivePauseRange.IsNone, Is.True);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheBatchProcessingAlwaysPauses()
|
||||
{
|
||||
Assert.That(PauseRange.GetEffective(BATCH_PROCESSING, 0, UNLOCKED, 0, UNLOCKED).IsNone, Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheLimitsAllowTheirShortestAndLongestPause()
|
||||
{
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(INDEXING.Allows(0), Is.True);
|
||||
Assert.That(INDEXING.Allows(-1), Is.False);
|
||||
Assert.That(INDEXING.Allows(300), Is.True);
|
||||
Assert.That(INDEXING.Allows(301), Is.False);
|
||||
Assert.That(BATCH_PROCESSING.Allows(5), Is.False);
|
||||
Assert.That(BATCH_PROCESSING.Allows(6), Is.True);
|
||||
Assert.That(BATCH_PROCESSING.Allows(300), Is.True);
|
||||
Assert.That(BATCH_PROCESSING.Allows(301), Is.False);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user