Skip to content

Commit 2684611

Browse files
authored
test(apisix-standalone): add inline upstream update 2 times case (#327)
1 parent fa15268 commit 2684611

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

libs/backend-apisix-standalone/e2e/resources/service-inline-upstream.e2e-spec.ts

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,41 @@ describe('Service E2E - inline upstream', () => {
108108
expect(rawConfig?.stream_routes_conf_version).toBeUndefined();
109109
});
110110

111-
it('Delete service', async () => {
111+
it('Update inlined upstream again', async () => {
112112
vi.useFakeTimers();
113113
vi.setSystemTime(300);
114114

115+
const newConfig = structuredClone(config);
116+
newConfig.services[0].upstream.nodes = [];
117+
118+
const events = DifferV3.diff(newConfig, await dumpConfiguration(backend));
119+
expect(events).toHaveLength(1);
120+
expect(events[0].type).toEqual(ADCSDK.EventType.UPDATE);
121+
expect(events[0].resourceType).toEqual(ADCSDK.ResourceType.SERVICE);
122+
expect(events[0].diff?.[0].path?.[0]).toEqual('upstream');
123+
124+
return syncEvents(backend, events);
125+
});
126+
127+
it('Check configuration', () => {
128+
const rawConfig = rawConfigCache.get(cacheKey);
129+
expect(rawConfig?.upstreams?.[0].modifiedIndex).toEqual(300);
130+
expect(rawConfig?.upstreams?.[0].nodes).toHaveLength(0);
131+
expect(rawConfig?.services?.[0].modifiedIndex).toEqual(100);
132+
expect(rawConfig?.upstreams_conf_version).toEqual(300);
133+
expect(rawConfig?.services_conf_version).toEqual(100);
134+
expect(rawConfig?.consumers_conf_version).toBeUndefined();
135+
expect(rawConfig?.global_rules_conf_version).toBeUndefined();
136+
expect(rawConfig?.plugin_metadata_conf_version).toBeUndefined();
137+
expect(rawConfig?.routes_conf_version).toBeUndefined();
138+
expect(rawConfig?.ssls_conf_version).toBeUndefined();
139+
expect(rawConfig?.stream_routes_conf_version).toBeUndefined();
140+
});
141+
142+
it('Delete service', async () => {
143+
vi.useFakeTimers();
144+
vi.setSystemTime(400);
145+
115146
const events = DifferV3.diff({}, await dumpConfiguration(backend));
116147
expect(events).toHaveLength(1);
117148
expect(events[0].type).toEqual(ADCSDK.EventType.DELETE);
@@ -124,7 +155,7 @@ describe('Service E2E - inline upstream', () => {
124155
const rawConfig = rawConfigCache.get(cacheKey);
125156
expect(rawConfig?.upstreams).toHaveLength(0);
126157
expect(rawConfig?.services).toHaveLength(0);
127-
expect(rawConfig?.upstreams_conf_version).toEqual(300);
128-
expect(rawConfig?.services_conf_version).toEqual(300);
158+
expect(rawConfig?.upstreams_conf_version).toEqual(400);
159+
expect(rawConfig?.services_conf_version).toEqual(400);
129160
});
130161
});

libs/backend-apisix-standalone/src/operator.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { DifferV3 } from '@api7/adc-differ';
21
import * as ADCSDK from '@api7/adc-sdk';
32
import axios, {
43
type AxiosError,
54
type AxiosInstance,
65
type AxiosResponse,
76
} from 'axios';
8-
import { cloneDeep, isNil, unset } from 'lodash';
7+
import { cloneDeep, unset } from 'lodash';
98
import { createHash } from 'node:crypto';
109
import {
1110
type ObservableInput,

0 commit comments

Comments
 (0)