TaskManager refactoring
This commit is contained in:
@@ -27,7 +27,7 @@ type
|
||||
[IgnoreMemoryLeaks(true)]
|
||||
TTestMycGateFuncFuture = class(TObject)
|
||||
private
|
||||
FTaskFactory: IMycThreadPool;
|
||||
FTaskFactory: IThreadPool;
|
||||
FProcExecutionCount: Integer; // Counter for side effects of AProc
|
||||
FSharedCounter: Integer; // For Fan-Out test side effects
|
||||
public
|
||||
@@ -156,7 +156,7 @@ end;
|
||||
procedure TTestMycGateFuncFuture.Test_ExceptionInProc_HandledAsPlanned;
|
||||
var
|
||||
LFuture: TFuture<Integer>.IFuture;
|
||||
LLocalTaskFactory: IMycThreadPool;
|
||||
LLocalTaskFactory: IThreadPool;
|
||||
LInitStateAsState: TState.IState;
|
||||
LResultValue: Integer;
|
||||
LExpectedExceptionRaisedByFactory: Boolean;
|
||||
@@ -288,7 +288,7 @@ begin
|
||||
end
|
||||
);
|
||||
LSub1 := TLatchNotifierSubscriber.Create(LGateLatch);
|
||||
Subscriptions[1] := LPrerequisiteFuture1.Done.Subscribe(LSub1); // Subscribe to PF1's completion [cite: 56, 188, 306]
|
||||
Subscriptions[1] := LPrerequisiteFuture1.Done.Signal.Subscribe(LSub1); // Subscribe to PF1's completion [cite: 56, 188, 306]
|
||||
|
||||
// PrerequisiteFuture2
|
||||
LInitStateP2 := TLatch.CreateLatch(1); // Controllable init state for PF2
|
||||
@@ -303,7 +303,7 @@ begin
|
||||
end
|
||||
);
|
||||
LSub2 := TLatchNotifierSubscriber.Create(LGateLatch);
|
||||
Subscriptions[2] := LPrerequisiteFuture2.Done.Subscribe(LSub2); // Subscribe to PF2's completion
|
||||
Subscriptions[2] := LPrerequisiteFuture2.Done.Signal.Subscribe(LSub2); // Subscribe to PF2's completion
|
||||
|
||||
// --- Execution & Verification ---
|
||||
Assert.IsFalse(LMainFuture.Done.IsSet, 'MainFuture should not be done yet.');
|
||||
|
||||
+1
-72
@@ -17,7 +17,7 @@ type
|
||||
[IgnoreMemoryLeaks(true)]
|
||||
TMycTaskFactoryTests = class(TObject)
|
||||
private
|
||||
FFactory: IMycThreadPool;
|
||||
FFactory: IThreadPool;
|
||||
public
|
||||
[Setup]
|
||||
procedure Setup;
|
||||
@@ -27,12 +27,6 @@ type
|
||||
[Test]
|
||||
procedure TestFactoryCreationAndTeardown;
|
||||
[Test]
|
||||
procedure TestCreateThreadExecutesAndSignals;
|
||||
[Test]
|
||||
procedure TestRunImmediateJob;
|
||||
[Test]
|
||||
procedure TestRunDelayedJobExecutesAfterAllNotifies;
|
||||
[Test]
|
||||
procedure TestWaitForAlreadySetState;
|
||||
[Test]
|
||||
procedure TestThreadInfoMethods;
|
||||
@@ -67,71 +61,6 @@ begin
|
||||
Assert.IsNotNull(FFactory, 'Factory should be created');
|
||||
end;
|
||||
|
||||
procedure TMycTaskFactoryTests.TestCreateThreadExecutesAndSignals;
|
||||
var
|
||||
executed: Boolean;
|
||||
threadState: TState.IState;
|
||||
procWrapper: TProc;
|
||||
begin
|
||||
executed := False;
|
||||
procWrapper := procedure begin executed := True; end;
|
||||
|
||||
threadState := FFactory.CreateThread(procWrapper); // CreateThread in TaskFactory now uses TMycLatch.CreateLatch
|
||||
Assert.IsNotNull(threadState, 'CreateThread should return a valid state object');
|
||||
|
||||
FFactory.WaitFor(threadState);
|
||||
Assert.IsTrue(executed, 'Procedure in created thread should have executed');
|
||||
end;
|
||||
|
||||
procedure TMycTaskFactoryTests.TestRunImmediateJob;
|
||||
var
|
||||
jobExecuted: Boolean;
|
||||
jobCompletedLatch: TLatch.ILatch;
|
||||
begin
|
||||
jobExecuted := False;
|
||||
jobCompletedLatch := TLatch.CreateLatch(1); // Changed from Signals.CreateLatch
|
||||
|
||||
FFactory
|
||||
.Run(
|
||||
procedure
|
||||
begin
|
||||
jobExecuted := True;
|
||||
jobCompletedLatch.Notify;
|
||||
end)
|
||||
.Notify;
|
||||
|
||||
FFactory.WaitFor(jobCompletedLatch.State);
|
||||
Assert.IsTrue(jobExecuted, 'Immediate job should have executed');
|
||||
end;
|
||||
|
||||
procedure TMycTaskFactoryTests.TestRunDelayedJobExecutesAfterAllNotifies;
|
||||
var
|
||||
jobExecuted: Boolean;
|
||||
jobCompletedLatch: TLatch.ILatch;
|
||||
subscriber: TSignal.ISubscriber;
|
||||
begin
|
||||
jobExecuted := False;
|
||||
jobCompletedLatch := TLatch.CreateLatch(1); // Changed from Signals.CreateLatch
|
||||
|
||||
subscriber :=
|
||||
FFactory.Run(
|
||||
procedure
|
||||
begin
|
||||
jobExecuted := True;
|
||||
jobCompletedLatch.Notify;
|
||||
end
|
||||
);
|
||||
|
||||
Assert.IsNotNull(subscriber, 'Run should return a subscriber for delayed job');
|
||||
// Use TMycLatch.Null for comparison
|
||||
Assert.AreNotEqual<TSignal.ISubscriber>(TLatch.Null, subscriber, 'Subscriber should not be TMycLatch.Null for StartCount > 0');
|
||||
|
||||
subscriber.Notify;
|
||||
|
||||
FFactory.WaitFor(jobCompletedLatch.State);
|
||||
Assert.IsTrue(jobExecuted, 'Delayed job should execute after all notifications');
|
||||
end;
|
||||
|
||||
procedure TMycTaskFactoryTests.TestWaitForAlreadySetState;
|
||||
var
|
||||
alreadySetLatch: TLatch.ILatch;
|
||||
|
||||
Reference in New Issue
Block a user