From 37f3c89bce3a1925e7a0e79eba7847b6fe740fe9 Mon Sep 17 00:00:00 2001 From: bzp2010 Date: Mon, 25 Aug 2025 10:03:00 +0800 Subject: [PATCH 1/2] test(apisix-standalone): add inline upstream update 2times case --- .../service-inline-upstream.e2e-spec.ts | 37 +++++++++++++++++-- .../backend-apisix-standalone/src/operator.ts | 3 +- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/libs/backend-apisix-standalone/e2e/resources/service-inline-upstream.e2e-spec.ts b/libs/backend-apisix-standalone/e2e/resources/service-inline-upstream.e2e-spec.ts index 3074505..0b8475f 100644 --- a/libs/backend-apisix-standalone/e2e/resources/service-inline-upstream.e2e-spec.ts +++ b/libs/backend-apisix-standalone/e2e/resources/service-inline-upstream.e2e-spec.ts @@ -108,10 +108,41 @@ describe('Service E2E - inline upstream', () => { expect(rawConfig?.stream_routes_conf_version).toBeUndefined(); }); - it('Delete service', async () => { + it('Update inlined upstream agent', async () => { vi.useFakeTimers(); vi.setSystemTime(300); + const newConfig = structuredClone(config); + newConfig.services[0].upstream.nodes = []; + + const events = DifferV3.diff(newConfig, await dumpConfiguration(backend)); + expect(events).toHaveLength(1); + expect(events[0].type).toEqual(ADCSDK.EventType.UPDATE); + expect(events[0].resourceType).toEqual(ADCSDK.ResourceType.SERVICE); + expect(events[0].diff?.[0].path?.[0]).toEqual('upstream'); + + return syncEvents(backend, events); + }); + + it('Check configuration', () => { + const rawConfig = rawConfigCache.get(cacheKey); + expect(rawConfig?.upstreams?.[0].modifiedIndex).toEqual(300); + expect(rawConfig?.upstreams?.[0].nodes).toHaveLength(0); + expect(rawConfig?.services?.[0].modifiedIndex).toEqual(100); + expect(rawConfig?.upstreams_conf_version).toEqual(300); + expect(rawConfig?.services_conf_version).toEqual(100); + expect(rawConfig?.consumers_conf_version).toBeUndefined(); + expect(rawConfig?.global_rules_conf_version).toBeUndefined(); + expect(rawConfig?.plugin_metadata_conf_version).toBeUndefined(); + expect(rawConfig?.routes_conf_version).toBeUndefined(); + expect(rawConfig?.ssls_conf_version).toBeUndefined(); + expect(rawConfig?.stream_routes_conf_version).toBeUndefined(); + }); + + it('Delete service', async () => { + vi.useFakeTimers(); + vi.setSystemTime(400); + const events = DifferV3.diff({}, await dumpConfiguration(backend)); expect(events).toHaveLength(1); expect(events[0].type).toEqual(ADCSDK.EventType.DELETE); @@ -124,7 +155,7 @@ describe('Service E2E - inline upstream', () => { const rawConfig = rawConfigCache.get(cacheKey); expect(rawConfig?.upstreams).toHaveLength(0); expect(rawConfig?.services).toHaveLength(0); - expect(rawConfig?.upstreams_conf_version).toEqual(300); - expect(rawConfig?.services_conf_version).toEqual(300); + expect(rawConfig?.upstreams_conf_version).toEqual(400); + expect(rawConfig?.services_conf_version).toEqual(400); }); }); diff --git a/libs/backend-apisix-standalone/src/operator.ts b/libs/backend-apisix-standalone/src/operator.ts index 4b36014..889ad13 100644 --- a/libs/backend-apisix-standalone/src/operator.ts +++ b/libs/backend-apisix-standalone/src/operator.ts @@ -1,11 +1,10 @@ -import { DifferV3 } from '@api7/adc-differ'; import * as ADCSDK from '@api7/adc-sdk'; import axios, { type AxiosError, type AxiosInstance, type AxiosResponse, } from 'axios'; -import { cloneDeep, isNil, unset } from 'lodash'; +import { cloneDeep, unset } from 'lodash'; import { createHash } from 'node:crypto'; import { type ObservableInput, From ffa986d32dca392c402a7f11276213b4753003aa Mon Sep 17 00:00:00 2001 From: bzp2010 Date: Mon, 25 Aug 2025 10:08:35 +0800 Subject: [PATCH 2/2] fix typo --- .../e2e/resources/service-inline-upstream.e2e-spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/backend-apisix-standalone/e2e/resources/service-inline-upstream.e2e-spec.ts b/libs/backend-apisix-standalone/e2e/resources/service-inline-upstream.e2e-spec.ts index 0b8475f..0b9cb15 100644 --- a/libs/backend-apisix-standalone/e2e/resources/service-inline-upstream.e2e-spec.ts +++ b/libs/backend-apisix-standalone/e2e/resources/service-inline-upstream.e2e-spec.ts @@ -108,7 +108,7 @@ describe('Service E2E - inline upstream', () => { expect(rawConfig?.stream_routes_conf_version).toBeUndefined(); }); - it('Update inlined upstream agent', async () => { + it('Update inlined upstream again', async () => { vi.useFakeTimers(); vi.setSystemTime(300);