Skip to content

Commit 6c983ea

Browse files
committed
Simplify tests and add comments.
1 parent 87abec2 commit 6c983ea

2 files changed

Lines changed: 26 additions & 12 deletions

File tree

packages/sync-rules/src/sync_plan/plan_equality_serialized.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,26 @@ export interface SerializedBucketDataSourceWithDataSources {
1010
dataSources: readonly SerializedDataSource[];
1111
}
1212

13-
export const serializedStreamDataSourceEquality = jsonEquality<SerializedDataSource>();
14-
13+
/**
14+
* Equality for SerializedParameterIndexLookupCreator.
15+
*
16+
* This compares the JSON form directly. These are self-contained and use a stable serialization form, so it's
17+
* safe to compare this way.
18+
*
19+
* These are only considered equal if the lookupName remains the same, so may be affected by changing order of queries.
20+
*/
1521
export const serializedStreamParameterIndexLookupCreatorEquality =
1622
jsonEquality<SerializedParameterIndexLookupCreator>();
1723

24+
/**
25+
* SerializedBucketDataSource is not safe to compare _directly_, since it contains index references to SerializedDataSource
26+
* in the serialized sync plan. However, each SerializedDataSource is self-contained and safe to compare directly.
27+
*
28+
* So we compare the SerializedDataSource excluding `bucket.sources`, as well as the resolved SerializedDataSources (order independent).
29+
* The caller is responsible for resolving the SerializedDataSources.
30+
*
31+
* These are only considered equal if uniqueName is the same, so may be affected by changing order of joins/subqueries.
32+
*/
1833
export const serializedStreamBucketDataSourceEquality: Equality<SerializedBucketDataSourceWithDataSources> = {
1934
hash(hasher, value) {
2035
hasher.addString(JSON.stringify(bucketIdentity(value)));

packages/sync-rules/test/src/sync_plan/evaluator/bucket_data_source_equality.test.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, expect } from 'vitest';
1+
import { describe, expect, it } from 'vitest';
22
import { StableHasher } from '../../../../src/compiler/equality.js';
33
import {
44
BucketDataSource,
@@ -8,10 +8,9 @@ import {
88
SyncConfig
99
} from '../../../../src/index.js';
1010
import { compileToSyncPlanWithoutErrors } from '../../compiler/utils.js';
11-
import { syncTest } from './utils.js';
1211

1312
describe('prepared bucket data source equality', () => {
14-
syncTest('matches equivalent prepared bucket sources from different plans', ({ sync }) => {
13+
it('matches equivalent prepared bucket sources from different plans', () => {
1514
const firstYaml = `
1615
config:
1716
edition: 3
@@ -31,7 +30,7 @@ streams:
3130
expectSerializedBucketSources(firstYaml, secondYaml, true);
3231
});
3332

34-
syncTest('does not match when output columns differ', ({ sync }) => {
33+
it('does not match when output columns differ', () => {
3534
const firstYaml = `
3635
config:
3736
edition: 3
@@ -51,7 +50,7 @@ streams:
5150
expectSerializedBucketSources(firstYaml, secondYaml, false);
5251
});
5352

54-
syncTest('does not match when partitioning differs', ({ sync }) => {
53+
it('does not match when partitioning differs', () => {
5554
const firstYaml = `
5655
config:
5756
edition: 3
@@ -71,7 +70,7 @@ streams:
7170
expectSerializedBucketSources(firstYaml, secondYaml, false);
7271
});
7372

74-
syncTest('does not match equivalent bucket sources with different stream names', ({ sync }) => {
73+
it('does not match equivalent bucket sources with different stream names', () => {
7574
const firstYaml = `
7675
config:
7776
edition: 3
@@ -95,7 +94,7 @@ streams:
9594
expectSerializedBucketSources(firstYaml, secondYaml, false, true);
9695
});
9796

98-
syncTest('matches when subqueries differ but the data source does not', ({ sync }) => {
97+
it('matches when subqueries differ but the data source does not', () => {
9998
const firstYaml = `
10099
config:
101100
edition: 3
@@ -123,7 +122,7 @@ streams:
123122
expectSerializedBucketSources(firstYaml, secondYaml, true);
124123
});
125124

126-
syncTest('matches when only bucket input parameters differ', ({ sync }) => {
125+
it('matches when only bucket input parameters differ', () => {
127126
const firstYaml = `
128127
config:
129128
edition: 3
@@ -143,7 +142,7 @@ streams:
143142
expectSerializedBucketSources(firstYaml, secondYaml, true);
144143
});
145144

146-
syncTest('matches buckets with the same data sources in a different order', ({ sync }) => {
145+
it('matches buckets with the same data sources in a different order', () => {
147146
const firstYaml = `
148147
config:
149148
edition: 3
@@ -167,7 +166,7 @@ streams:
167166
expectSerializedBucketSources(firstYaml, secondYaml, true);
168167
});
169168

170-
syncTest('compares table-valued function output expressions by their bindings', ({ sync }) => {
169+
it('compares table-valued function output expressions by their bindings', () => {
171170
const firstYaml = `
172171
config:
173172
edition: 3

0 commit comments

Comments
 (0)