Refactoring
This commit is contained in:
+3
-1
@@ -24,7 +24,9 @@ uses
|
||||
TestTasks in 'TestTasks.pas',
|
||||
TestSignals_Dirty in 'TestSignals_Dirty.pas',
|
||||
Myc.Futures in '..\Src\Myc.Futures.pas',
|
||||
TestFutures in 'TestFutures.pas';
|
||||
TestFutures in 'TestFutures.pas',
|
||||
Myc.TaskManager in '..\Src\Myc.TaskManager.pas',
|
||||
Myc.Core.Futures in '..\Src\Myc.Core.Futures.pas';
|
||||
|
||||
{ keep comment here to protect the following conditional from being removed by the IDE when adding a unit }
|
||||
{$IFNDEF TESTINSIGHT}
|
||||
|
||||
@@ -124,6 +124,8 @@ $(PostBuildEvent)]]></PostBuildEvent>
|
||||
<DCCReference Include="TestSignals_Dirty.pas"/>
|
||||
<DCCReference Include="..\Src\Myc.Futures.pas"/>
|
||||
<DCCReference Include="TestFutures.pas"/>
|
||||
<DCCReference Include="..\Src\Myc.TaskManager.pas"/>
|
||||
<DCCReference Include="..\Src\Myc.Core.Futures.pas"/>
|
||||
<BuildConfiguration Include="Base">
|
||||
<Key>Base</Key>
|
||||
</BuildConfiguration>
|
||||
@@ -1129,6 +1131,15 @@ $(PostBuildEvent)]]></PostBuildEvent>
|
||||
<Platform value="Win32">True</Platform>
|
||||
<Platform value="Win64">True</Platform>
|
||||
</Platforms>
|
||||
<MMX>
|
||||
<UsesClauseFormatter AutoFormat="0" UseDefault="0">
|
||||
<GroupNames>Winapi;System.Win;System;Data;REST;Xml;Vcl;FMX</GroupNames>
|
||||
</UsesClauseFormatter>
|
||||
<Parser>
|
||||
<Defines/>
|
||||
<IfExpressions/>
|
||||
</Parser>
|
||||
</MMX>
|
||||
</BorlandProject>
|
||||
<ProjectFileVersion>12</ProjectFileVersion>
|
||||
</ProjectExtensions>
|
||||
|
||||
+15
-17
@@ -8,7 +8,7 @@ uses
|
||||
System.SyncObjs,
|
||||
Myc.Signals, // For IMycLatch, TMycLatch, IMycState, IMycSubscriber [cite: 62, 68, 53, 45]
|
||||
Myc.Core.Tasks, // For IMycTaskFactory, TMycTaskFactory [cite: 97, 113]
|
||||
Myc.Futures; // For IMycFuture, TMycInitStateFuncFuture
|
||||
Myc.Futures, Myc.Core.Futures; // For IMycFuture, TMycInitStateFuncFuture
|
||||
|
||||
type
|
||||
// Helper class to notify a latch when its Notify method is called.
|
||||
@@ -207,12 +207,8 @@ procedure TTestMycInitStateFuncFuture.Test_GetResult_BeforeDone_RaisesException;
|
||||
var
|
||||
LFuture: IMycFuture<Integer>;
|
||||
LInitLatch: IMycLatch;
|
||||
LExpectedExceptionRaised: Boolean;
|
||||
const
|
||||
CExpectedExceptionMessage = 'Result is not yet available for the future.';
|
||||
begin
|
||||
LExpectedExceptionRaised := False;
|
||||
LInitLatch := TMycLatch.CreateLatch(1); // Create a latch that is not yet set [cite: 77, 212, 330]
|
||||
LInitLatch := TMycLatch.CreateLatch(1);
|
||||
|
||||
LFuture := TMycInitStateFuncFuture<Integer>.Create(FTaskFactory, LInitLatch.State,
|
||||
function: Integer
|
||||
@@ -223,19 +219,21 @@ begin
|
||||
|
||||
Assert.IsFalse(LFuture.Done.IsSet, 'Future should not be marked as done initially.');
|
||||
|
||||
try
|
||||
LFuture.GetResult;
|
||||
except
|
||||
on E: Exception do
|
||||
Assert.WillRaise(
|
||||
procedure
|
||||
begin
|
||||
Assert.AreEqual(CExpectedExceptionMessage, E.Message, 'Exception message mismatch.');
|
||||
LExpectedExceptionRaised := True;
|
||||
end;
|
||||
end;
|
||||
Assert.IsTrue(LExpectedExceptionRaised, 'Calling GetResult before done should raise an exception.');
|
||||
LFuture.GetResult;
|
||||
end );
|
||||
|
||||
LInitLatch.Notify; // [cite: 80, 215, 333]
|
||||
FTaskFactory.WaitFor(LFuture.Done); //
|
||||
LInitLatch.Notify;
|
||||
|
||||
FTaskFactory.WaitFor(LFuture.Done);
|
||||
|
||||
Assert.WillNotRaise(
|
||||
procedure
|
||||
begin
|
||||
LFuture.GetResult;
|
||||
end );
|
||||
end;
|
||||
|
||||
procedure TTestMycInitStateFuncFuture.Test_FanIn_OneFutureWaitsForMultipleOthers;
|
||||
|
||||
Reference in New Issue
Block a user