Skip to content

Commit

Permalink
fix: race condition with picked nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
theoephraim committed Dec 12, 2024
1 parent 1a52755 commit 0bbd0fe
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changeset/rare-zebras-cheer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@dmno/configraph": patch
"dmno": patch
---

fix issue with picked nodes and parallelized resolution
5 changes: 3 additions & 2 deletions packages/configraph/src/resolvers/pick.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createResolver } from '../resolvers';
import { createResolver, DependencyNotResolvedResolutionError } from '../resolvers';
import { ConfigraphNode } from '../config-node';

export function createdPickedValueResolver(
Expand All @@ -15,8 +15,9 @@ export function createdPickedValueResolver(
// since we handle resolution of services in the right order
// we can assume the picked value will be resolved already (if it was possible at all)
if (!sourceNode.isResolved) {
return new Error('picked value has not been resolved yet');
throw new DependencyNotResolvedResolutionError('picked value has not been resolved yet');
}

if (valueTransform) {
return valueTransform(sourceNode.resolvedValue);
} else {
Expand Down
21 changes: 21 additions & 0 deletions packages/configraph/test/pick.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { setTimeout as delay } from 'node:timers/promises';
import { nextTick } from 'node:process';
import { expect, test, describe } from 'vitest';
import { Configraph } from '@dmno/configraph';

Expand Down Expand Up @@ -182,4 +184,23 @@ describe('pick behaviour', async () => {
});
});
});
describe('pick resolution', () => {
test('picked items will wait for source to resolve', async () => {
const g = new Configraph();
g.createEntity({
configSchema: {
delayedSource: {
value: async () => {
await delay(1);
return 'resolved-after-delay';
},
},
},
});
const e = g.createEntity({ pickSchema: ['delayedSource'] });
await g.resolveConfig();
expect(e.configNodes.delayedSource.resolutionError).toBeUndefined();
expect(e.configNodes.delayedSource.resolvedValue).toEqual('resolved-after-delay');
});
});
});

0 comments on commit 0bbd0fe

Please sign in to comment.