Skip to content

Commit

Permalink
feat!: use new eval/sync protos (requires flagd v0.7.3+) (#762)
Browse files Browse the repository at this point in the history
Signed-off-by: Todd Baert <[email protected]>
  • Loading branch information
toddbaert authored Feb 13, 2024
1 parent 872b5ab commit 4da9deb
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 20 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ jobs:

services:
flagd:
image: ghcr.io/open-feature/flagd-testbed:v0.4.11
image: ghcr.io/open-feature/flagd-testbed:v0.5.1
ports:
- 8013:8013
flagd-unstable:
image: ghcr.io/open-feature/flagd-testbed-unstable:v0.4.11
image: ghcr.io/open-feature/flagd-testbed-unstable:v0.5.1
ports:
- 8014:8013
sync:
image: ghcr.io/open-feature/sync-testbed:v0.4.11
image: ghcr.io/open-feature/sync-testbed:v0.5.1
ports:
- 9090:9090
sync-unstable:
image: ghcr.io/open-feature/sync-testbed-unstable:v0.4.11
image: ghcr.io/open-feature/sync-testbed-unstable:v0.5.1
ports:
- 9091:9090

Expand Down
4 changes: 2 additions & 2 deletions libs/providers/flagd-web/src/lib/flagd-web-provider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import {
StandardResolutionReasons,
} from '@openfeature/web-sdk';
import fetchMock from 'jest-fetch-mock';
import { Service } from '../proto/ts/schema/v1/schema_connect';
import { AnyFlag, EventStreamResponse, ResolveAllResponse } from '../proto/ts/schema/v1/schema_pb';
import { Service } from '../proto/ts/flagd/evaluation/v1/evaluation_connect';
import { AnyFlag, EventStreamResponse, ResolveAllResponse } from '../proto/ts/flagd/evaluation/v1/evaluation_pb';
import { FlagdWebProvider } from './flagd-web-provider';

const EVENT_CONFIGURATION_CHANGE = 'configuration_change';
Expand Down
4 changes: 2 additions & 2 deletions libs/providers/flagd-web/src/lib/flagd-web-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import {
StandardResolutionReasons,
TypeMismatchError,
} from '@openfeature/web-sdk';
import { Service } from '../proto/ts/schema/v1/schema_connect';
import { AnyFlag } from '../proto/ts/schema/v1/schema_pb';
import { Service } from '../proto/ts/flagd/evaluation/v1/evaluation_connect';
import { AnyFlag } from '../proto/ts/flagd/evaluation/v1/evaluation_pb';
import { FlagdProviderOptions, getOptions } from './options';

export const ERROR_DISABLED = 'DISABLED';
Expand Down
2 changes: 1 addition & 1 deletion libs/providers/flagd/schemas
10 changes: 7 additions & 3 deletions libs/providers/flagd/src/e2e/step-definitions/flagd.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,17 @@ defineFeature(feature, (test) => {

test('Flag change event', ({ given, when, and, then }) => {
let ran = false;
let eventDetails: EventDetails<ProviderEvents> | undefined;
let flagsChanged: string[];

aFlagProviderIsSet(given);
when('a PROVIDER_CONFIGURATION_CHANGED handler is added', () => {
client.addHandler(ProviderEvents.ConfigurationChanged, async (details) => {
ran = true;
eventDetails = details;
// file writes are not atomic, so we get a few events in quick succession from the testbed
// some will not contain changes, this tolerates that; at least 1 should have our change
if (details?.flagsChanged?.length) {
flagsChanged = details?.flagsChanged;
}
});
});
and(/^a flag with key "(.*)" is modified$/, async () => {
Expand All @@ -55,7 +59,7 @@ defineFeature(feature, (test) => {
expect(ran).toBeTruthy();
});
and(/^the event details must indicate "(.*)" was altered$/, (flagName) => {
expect(eventDetails?.flagsChanged).toContain(flagName);
expect(flagsChanged).toContain(flagName);
});
});

Expand Down
2 changes: 1 addition & 1 deletion libs/providers/flagd/src/lib/flagd-provider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
ResolveStringRequest,
ResolveStringResponse,
ServiceClient,
} from '../proto/ts/schema/v1/schema';
} from '../proto/ts/flagd/evaluation/v1/evaluation';
import { EVENT_CONFIGURATION_CHANGE, EVENT_PROVIDER_READY } from './constants';
import { FlagdProvider } from './flagd-provider';
import { FlagChangeMessage, GRPCService } from './service/grpc/grpc-service';
Expand Down
2 changes: 1 addition & 1 deletion libs/providers/flagd/src/lib/service/grpc/grpc-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
ResolveStringRequest,
ResolveStringResponse,
ServiceClient,
} from '../../../proto/ts/schema/v1/schema';
} from '../../../proto/ts/flagd/evaluation/v1/evaluation';
import { Config } from '../../configuration';
import { DEFAULT_MAX_CACHE_SIZE, EVENT_CONFIGURATION_CHANGE, EVENT_PROVIDER_READY } from '../../constants';
import { FlagdProvider } from '../../flagd-provider';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GrpcFetch } from './grpc-fetch';
import { Config } from '../../../configuration';
import { FlagSyncServiceClient, SyncFlagsResponse, SyncState } from '../../../../proto/ts/sync/v1/sync_service';
import { FlagSyncServiceClient, SyncFlagsResponse } from '../../../../proto/ts/flagd/sync/v1/sync';
import { ConnectivityState } from '@grpc/grpc-js/build/src/connectivity-state';

let watchStateCallback: () => void = () => ({});
Expand Down Expand Up @@ -70,7 +70,7 @@ describe('grpc fetch', () => {
done(err);
});

onDataCallback({ flagConfiguration, state: SyncState.SYNC_STATE_ALL });
onDataCallback({ flagConfiguration });
});

it('should handle data sync reconnection', (done) => {
Expand All @@ -86,13 +86,13 @@ describe('grpc fetch', () => {
.then(() => {
try {
// Updated flags
onDataCallback({ flagConfiguration: updatedFlagConfig, state: SyncState.SYNC_STATE_ALL });
onDataCallback({ flagConfiguration: updatedFlagConfig });
// Stream error
onErrorCallback(new Error('Some connection error'));
// Force clearing
watchStateCallback();
// Reconnect
onDataCallback({ flagConfiguration: reconnectFlagConfig, state: SyncState.SYNC_STATE_ALL });
onDataCallback({ flagConfiguration: reconnectFlagConfig });

// Callback assertions
expect(dataCallback).toHaveBeenCalledTimes(3);
Expand All @@ -117,7 +117,7 @@ describe('grpc fetch', () => {
dataCallback.mockReturnValue(['test']);

// First connection
onDataCallback({ flagConfiguration: initFlagConfig, state: SyncState.SYNC_STATE_ALL });
onDataCallback({ flagConfiguration: initFlagConfig });
});

it('should handle error and watch channel for reconnect', (done) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ClientReadableStream, ServiceError, credentials } from '@grpc/grpc-js';
import { Logger } from '@openfeature/core';
import { GeneralError } from '@openfeature/server-sdk';
import { FlagSyncServiceClient, SyncFlagsRequest, SyncFlagsResponse } from '../../../../proto/ts/sync/v1/sync_service';
import { FlagSyncServiceClient, SyncFlagsRequest, SyncFlagsResponse } from '../../../../proto/ts/flagd/sync/v1/sync';
import { Config } from '../../../configuration';
import { DataFetch } from '../data-fetch';
import { closeStreamIfDefined } from '../../common';
Expand Down

0 comments on commit 4da9deb

Please sign in to comment.