Code formatting
This commit is contained in:
+54
-56
@@ -8,7 +8,8 @@ uses
|
||||
System.Classes,
|
||||
System.SyncObjs,
|
||||
Myc.Core.Tasks,
|
||||
Myc.Signals, Myc.Core.Signals,
|
||||
Myc.Signals,
|
||||
Myc.Core.Signals,
|
||||
Myc.Core.Atomic;
|
||||
|
||||
type
|
||||
@@ -73,10 +74,7 @@ var
|
||||
procWrapper: TProc;
|
||||
begin
|
||||
executed := False;
|
||||
procWrapper := procedure
|
||||
begin
|
||||
executed := True;
|
||||
end;
|
||||
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');
|
||||
@@ -93,12 +91,14 @@ begin
|
||||
jobExecuted := False;
|
||||
jobCompletedLatch := TLatch.Construct(1); // Changed from Signals.CreateLatch
|
||||
|
||||
FFactory.Run(
|
||||
procedure
|
||||
begin
|
||||
jobExecuted := True;
|
||||
jobCompletedLatch.Notify;
|
||||
end).Notify;
|
||||
FFactory
|
||||
.Run(
|
||||
procedure
|
||||
begin
|
||||
jobExecuted := True;
|
||||
jobCompletedLatch.Notify;
|
||||
end)
|
||||
.Notify;
|
||||
|
||||
FFactory.WaitFor(jobCompletedLatch.State);
|
||||
Assert.IsTrue(jobExecuted, 'Immediate job should have executed');
|
||||
@@ -113,12 +113,14 @@ begin
|
||||
jobExecuted := False;
|
||||
jobCompletedLatch := TLatch.Construct(1); // Changed from Signals.CreateLatch
|
||||
|
||||
subscriber := FFactory.Run(
|
||||
procedure
|
||||
begin
|
||||
jobExecuted := True;
|
||||
jobCompletedLatch.Notify;
|
||||
end);
|
||||
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
|
||||
@@ -130,7 +132,6 @@ begin
|
||||
Assert.IsTrue(jobExecuted, 'Delayed job should execute after all notifications');
|
||||
end;
|
||||
|
||||
|
||||
procedure TMycTaskFactoryTests.TestWaitForAlreadySetState;
|
||||
var
|
||||
alreadySetLatch: IMycLatch;
|
||||
@@ -161,12 +162,13 @@ begin
|
||||
Assert.IsFalse(FFactory.InWorkerThread, 'Test method itself should not be in a factory worker thread');
|
||||
|
||||
FFactory.EnqueueJob(
|
||||
procedure
|
||||
begin
|
||||
inMainThreadInJob := FFactory.InMainThread;
|
||||
inWorkerThreadInJob := FFactory.InWorkerThread;
|
||||
jobDoneLatch.Notify;
|
||||
end);
|
||||
procedure
|
||||
begin
|
||||
inMainThreadInJob := FFactory.InMainThread;
|
||||
inWorkerThreadInJob := FFactory.InWorkerThread;
|
||||
jobDoneLatch.Notify;
|
||||
end
|
||||
);
|
||||
|
||||
FFactory.WaitFor(jobDoneLatch.State);
|
||||
|
||||
@@ -181,22 +183,20 @@ begin
|
||||
jobDoneLatch := TLatch.Construct(1);
|
||||
|
||||
FFactory.EnqueueJob(
|
||||
procedure
|
||||
begin
|
||||
try
|
||||
raise TMycTaskFactory.ETaskException.Create('Test Exception From Job');
|
||||
finally
|
||||
jobDoneLatch.Notify;
|
||||
end;
|
||||
end);
|
||||
procedure
|
||||
begin
|
||||
try
|
||||
raise TMycTaskFactory.ETaskException.Create('Test Exception From Job');
|
||||
finally
|
||||
jobDoneLatch.Notify;
|
||||
end;
|
||||
end
|
||||
);
|
||||
|
||||
Assert.WillRaise(
|
||||
procedure
|
||||
begin
|
||||
FFactory.WaitFor(jobDoneLatch.State);
|
||||
end,
|
||||
TMycTaskFactory.ETaskException,
|
||||
'WaitFor should re-raise the exception from the job'
|
||||
procedure begin FFactory.WaitFor(jobDoneLatch.State); end,
|
||||
TMycTaskFactory.ETaskException,
|
||||
'WaitFor should re-raise the exception from the job'
|
||||
);
|
||||
|
||||
var noExceptionRaised: Boolean := True;
|
||||
@@ -213,12 +213,9 @@ begin
|
||||
FFactory.Teardown;
|
||||
|
||||
Assert.WillRaise(
|
||||
procedure
|
||||
begin
|
||||
FFactory.EnqueueJob(procedure begin end);
|
||||
end,
|
||||
TMycTaskFactory.ETaskException,
|
||||
'Running a job on a torn-down factory should raise ETaskException'
|
||||
procedure begin FFactory.EnqueueJob(procedure begin end); end,
|
||||
TMycTaskFactory.ETaskException,
|
||||
'Running a job on a torn-down factory should raise ETaskException'
|
||||
);
|
||||
end;
|
||||
|
||||
@@ -233,18 +230,19 @@ begin
|
||||
dummyStateToWaitFor := TLatch.Construct(1).State;
|
||||
|
||||
FFactory.EnqueueJob(
|
||||
procedure
|
||||
begin
|
||||
try
|
||||
FFactory.WaitFor(dummyStateToWaitFor);
|
||||
except
|
||||
on E: TMycTaskFactory.ETaskException do
|
||||
begin
|
||||
exceptionCaughtInJob := True;
|
||||
end;
|
||||
end;
|
||||
jobDoneLatch.Notify;
|
||||
end);
|
||||
procedure
|
||||
begin
|
||||
try
|
||||
FFactory.WaitFor(dummyStateToWaitFor);
|
||||
except
|
||||
on E: TMycTaskFactory.ETaskException do
|
||||
begin
|
||||
exceptionCaughtInJob := True;
|
||||
end;
|
||||
end;
|
||||
jobDoneLatch.Notify;
|
||||
end
|
||||
);
|
||||
|
||||
FFactory.WaitFor(jobDoneLatch.State);
|
||||
Assert.IsTrue(exceptionCaughtInJob, 'WaitFor called within a worker thread job should raise ETaskException');
|
||||
|
||||
Reference in New Issue
Block a user