Skip to content
This repository was archived by the owner on Dec 13, 2019. It is now read-only.

Commit a0b221c

Browse files
authored
Fix incorrectly implemented queuing logic (#2336)
1 parent 6ebc5d6 commit a0b221c

File tree

3 files changed

+45
-37
lines changed

3 files changed

+45
-37
lines changed

packages/node/src/methods/queued-execution.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,18 @@ export async function executeFunctionWithinQueues(
1212
queueList: Queue[],
1313
f: () => Promise<any>
1414
) {
15-
let promise;
15+
let executionPromise;
1616

1717
function executeCached() {
18-
if (!promise) promise = f();
19-
return promise;
18+
if (!executionPromise) executionPromise = f();
19+
return executionPromise;
2020
}
2121

2222
if (queueList.length > 0) {
23-
for (const queue of queueList) queue.add(executeCached);
24-
for (const queue of queueList) await queue;
25-
return promise;
23+
const promiseList: Promise<any>[] = [];
24+
for (const queue of queueList) promiseList.push(queue.add(executeCached));
25+
for (const promise of promiseList) await promise;
26+
return executionPromise;
2627
}
2728

2829
return executeCached();

packages/node/test/integration/install-concurrent-virtual.spec.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,25 @@ describe("Concurrently installing virtual applications with same intermediary",
4747
);
4848
});
4949

50-
it("can handle two TicTacToeApp proposals", async done => {
50+
it("can handle two TicTacToeApp proposals syncronously made", done => {
51+
let i = 0;
52+
53+
nodeA.on(NODE_EVENTS.INSTALL_VIRTUAL, () => {
54+
i += 1;
55+
if (i === 2) done();
56+
});
57+
58+
for (const i of Array(2)) {
59+
installVirtualApp(
60+
nodeA,
61+
nodeB,
62+
nodeC,
63+
(global["networkContext"] as NetworkContextForTestSuite).TicTacToeApp
64+
);
65+
}
66+
});
67+
68+
it("can handle two TicTacToeApp proposals asyncronously made", async done => {
5169
let i = 0;
5270

5371
nodeA.on(NODE_EVENTS.INSTALL_VIRTUAL, () => {

packages/node/test/integration/utils.ts

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -614,38 +614,34 @@ export async function makeVirtualProposal(
614614
Zero,
615615
CONVENTION_FOR_ETH_TOKEN_ADDRESS
616616
);
617+
617618
const params = virtualProposalRpc.parameters as NodeTypes.ProposeInstallVirtualParams;
619+
618620
const {
619621
result: {
620622
result: { appInstanceId }
621623
}
622-
} = await nodeA.rpcRouter.dispatch(
623-
jsonRpcDeserialize({
624-
params,
625-
jsonrpc: "2.0",
626-
method: NodeTypes.RpcMethodName.PROPOSE_INSTALL_VIRTUAL,
627-
id: Date.now()
628-
})
629-
);
630-
// expect(appInstanceId).toBeDefined();
624+
} = await nodeA.rpcRouter.dispatch({
625+
parameters: params,
626+
methodName: NodeTypes.RpcMethodName.PROPOSE_INSTALL_VIRTUAL,
627+
id: Date.now()
628+
});
629+
631630
return { appInstanceId, params };
632631
}
633632

634-
export function installTTTVirtual(
633+
export async function installTTTVirtual(
635634
node: Node,
636635
appInstanceId: string,
637636
intermediaryIdentifier: string
638637
) {
639-
const installVirtualReq = constructInstallVirtualRpc(
640-
appInstanceId,
641-
intermediaryIdentifier
638+
return await node.rpcRouter.dispatch(
639+
constructInstallVirtualRpc(appInstanceId, intermediaryIdentifier)
642640
);
643-
node.rpcRouter.dispatch(installVirtualReq);
644641
}
645642

646-
export function makeInstallCall(node: Node, appInstanceId: string) {
647-
const installRpc = constructInstallRpc(appInstanceId);
648-
return node.rpcRouter.dispatch(installRpc);
643+
export async function makeInstallCall(node: Node, appInstanceId: string) {
644+
return await node.rpcRouter.dispatch(constructInstallRpc(appInstanceId));
649645
}
650646

651647
export async function makeVirtualProposeCall(
@@ -766,24 +762,17 @@ export function getAppContext(
766762
appDefinition: string,
767763
initialState?: SolidityValueType
768764
): AppContext {
769-
let abiEncodings: AppABIEncodings;
770-
let initialAppState: SolidityValueType;
771-
772765
switch (appDefinition) {
773766
case (global["networkContext"] as NetworkContextForTestSuite).TicTacToeApp:
774-
initialAppState = initialState ? initialState : initialEmptyTTTState();
775-
abiEncodings = tttAbiEncodings;
776-
break;
767+
return {
768+
appDefinition,
769+
abiEncodings: tttAbiEncodings,
770+
initialState: initialState ? initialState : initialEmptyTTTState()
771+
};
777772

778773
default:
779-
throw Error(
774+
throw new Error(
780775
`Proposing the specified app is not supported: ${appDefinition}`
781776
);
782777
}
783-
784-
return {
785-
appDefinition,
786-
abiEncodings,
787-
initialState: initialAppState
788-
};
789778
}

0 commit comments

Comments
 (0)