Hi Blake,
Workflow 12 has no fault-injection harness, and it cannot re-run one failed activity in a terminated instance. You need less for this test than it seems, though: when your exception terminates the instance, Workflow records the value of every token automatically. Here is what the host does in each of your three areas.
1. Forcing the failure
SetToken itself has no failure mode to inject. In the Workflow 12 host it does no I/O: it sets a value in the instance's token collection, keyed by token name. The failure to test is an exception your Finalize code raises between two SetToken calls. There are two ways to cause one with the unmodified signed DLL:
- From input. If Finalize validates a value it reads from a token or property, set that value from the workflow so that Finalize throws after the HTML write in one run, and before the counter write in another.
- From a debugger. Laserfiche documents running a workflow inside the real Workflow service under the Visual Studio debugger, in Appendix C of the white paper "Building Custom Activities in Workflow 12 (C#)". That paper is installed with the Workflow SDK, in the SDK folder of the Workflow Designer installation (by default C:\Program Files\Laserfiche\Workflow Designer\SDK). On a test server:
- Stop the Workflow Server service.
- Set your project's debug start action to Laserfiche.Workflow.Service.exe in the Workflow installation folder, with the command-line argument -console.
- Start debugging. When the console shows "Hit <Enter> to exit", type run and answer the prompts for the workflow name, repository, sign-in and starting entry.
Breakpoints in Finalize are then hit inside the real host. From the debugger you can raise an exception just before the HTML SetToken call, or before the counter write. You need your own PDB files and source, which you have as the author. The prompt shows the repository password as you type it, so use a test account.
2. What Workflow keeps, and how to see it
Nothing is rolled back. Every SetToken call that finished before the exception stays in the instance's tokens, along with what Initialize and AppendRow wrote to tokens. This covers workflow tokens only. Anything your activities write elsewhere, such as a file or a database, is outside Workflow's control.
You do not need to add anything to the workflow to see that state. If the exception is unhandled, the instance terminates, and Workflow then records the value of every token in the instance. The setting is Track additional diagnostic data about the workflow, in the workflow's Terminated Workflow Options, and it is selected by default. To check it in the Workflow Designer, select a blank spot in the Designer Pane and click Configure termination notifications in the Properties Pane. Then open the terminated instance's details and look at the Tokens tab. In your first run the HTML token should be there and the counter token not yet written; in the second run, the HTML token is written and the counter write did not happen.
Token writes are lost only after a host failure. If the Workflow Server process stops while Finalize is running, the server reloads the instance from its last saved state when the service starts. Token writes made after that save are discarded, and the activities after it run again.
3. Retrying only Finalize in the same instance
A terminated instance cannot be resumed. The Workflow Server also does not retry an activity derived from CustomSingleEntryActivity: it runs directly, outside the server's task retry. The server's automatic retry covers task activities and, for repository errors, the older 8.0-style custom activity base classes. If your acceptance test needs the retry, build it into the test workflow.
Option A: retry inside the workflow.
- Initialize, then AppendRow (each runs once)
- Repeat, with the condition Done is not True and Limit number of repetitions to: 2
- Try-Catch
- Try: Finalize, then Assign Token Values (Done = True)
- Catch: Track Tokens (state after the failure), then Assign Token Values that change the fault-trigger input so the next pass succeeds
- After the Repeat: Track Tokens (final state), then a Conditional Decision whose branch for Done is not True holds an End Workflow activity with Action set to Current workflow, Workflow Status set to Terminated, and a Reason. A Repeat that reaches its limit simply continues, so without this check a failed retry would look like a pass.
Here the Try-Catch keeps the instance from terminating, so the automatic token recording from point 2 does not happen. That is why the Catch Branch has its own Track Tokens. A SetToken call with an existing token name replaces the value rather than appending to it, so the host does not duplicate the HTML or the counts. Duplicates can only come from Finalize itself, for example if it reads its earlier HTML or counter token and adds to it instead of rebuilding from the table state. Comparing the two snapshots tests exactly that.
Option B: a restart test. Put a Create Checkpoint activity between AppendRow and Finalize. If the Workflow Server process stops while Finalize is running, the server reloads the instance from the checkpoint when the service starts. It then runs Finalize again in the same instance, with the tokens as they were at the checkpoint. Stop the process (Task Manager or taskkill /f) rather than the service, because a clean service stop may save the instance at its current point instead. No reboot is needed.
If you want the server to do the retry instead, your activity would need to derive from one of the SDK's task activity base classes, such as CustomSingleEntryTaskActivity, whose task module sets its own retry options. That means a new build of your own custom activity DLL, signed with your own key. The Laserfiche assemblies stay as they are.
Documentation: