mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 04:57:40 +00:00
perf(test): statically import gateway reload deps
This commit is contained in:
@@ -7,6 +7,8 @@ import {
|
|||||||
clearAllDispatchers,
|
clearAllDispatchers,
|
||||||
getTotalPendingReplies,
|
getTotalPendingReplies,
|
||||||
} from "../auto-reply/reply/dispatcher-registry.js";
|
} from "../auto-reply/reply/dispatcher-registry.js";
|
||||||
|
import { createReplyDispatcher } from "../auto-reply/reply/reply-dispatcher.js";
|
||||||
|
import { getTotalQueueSize } from "../process/command-queue.js";
|
||||||
|
|
||||||
// Helper to flush all pending microtasks
|
// Helper to flush all pending microtasks
|
||||||
async function flushMicrotasks() {
|
async function flushMicrotasks() {
|
||||||
@@ -28,9 +30,6 @@ describe("gateway config reload during reply", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should defer restart until reply dispatcher completes", async () => {
|
it("should defer restart until reply dispatcher completes", async () => {
|
||||||
const { createReplyDispatcher } = await import("../auto-reply/reply/reply-dispatcher.js");
|
|
||||||
const { getTotalQueueSize } = await import("../process/command-queue.js");
|
|
||||||
|
|
||||||
// Create a dispatcher (simulating message handling)
|
// Create a dispatcher (simulating message handling)
|
||||||
let deliveredReplies: string[] = [];
|
let deliveredReplies: string[] = [];
|
||||||
const dispatcher = createReplyDispatcher({
|
const dispatcher = createReplyDispatcher({
|
||||||
|
|||||||
@@ -4,6 +4,12 @@
|
|||||||
* and ensures they get a reply before the gateway restarts.
|
* and ensures they get a reply before the gateway restarts.
|
||||||
*/
|
*/
|
||||||
import { describe, expect, it, vi, beforeEach, afterEach } from "vitest";
|
import { describe, expect, it, vi, beforeEach, afterEach } from "vitest";
|
||||||
|
import {
|
||||||
|
clearAllDispatchers,
|
||||||
|
getTotalPendingReplies,
|
||||||
|
} from "../auto-reply/reply/dispatcher-registry.js";
|
||||||
|
import { createReplyDispatcher } from "../auto-reply/reply/reply-dispatcher.js";
|
||||||
|
import { getTotalQueueSize } from "../process/command-queue.js";
|
||||||
|
|
||||||
describe("gateway restart deferral integration", () => {
|
describe("gateway restart deferral integration", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
@@ -14,15 +20,10 @@ describe("gateway restart deferral integration", () => {
|
|||||||
vi.restoreAllMocks();
|
vi.restoreAllMocks();
|
||||||
// Wait for any pending microtasks (from markComplete()) to complete
|
// Wait for any pending microtasks (from markComplete()) to complete
|
||||||
await Promise.resolve();
|
await Promise.resolve();
|
||||||
const { clearAllDispatchers } = await import("../auto-reply/reply/dispatcher-registry.js");
|
|
||||||
clearAllDispatchers();
|
clearAllDispatchers();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should defer restart until dispatcher completes with reply", async () => {
|
it("should defer restart until dispatcher completes with reply", async () => {
|
||||||
const { createReplyDispatcher } = await import("../auto-reply/reply/reply-dispatcher.js");
|
|
||||||
const { getTotalPendingReplies } = await import("../auto-reply/reply/dispatcher-registry.js");
|
|
||||||
const { getTotalQueueSize } = await import("../process/command-queue.js");
|
|
||||||
|
|
||||||
const events: string[] = [];
|
const events: string[] = [];
|
||||||
|
|
||||||
// T=0: Message received — dispatcher created (pending=1 reservation)
|
// T=0: Message received — dispatcher created (pending=1 reservation)
|
||||||
|
|||||||
@@ -3,6 +3,11 @@
|
|||||||
* This test MUST fail if "imsg rpc not running" would occur in production.
|
* This test MUST fail if "imsg rpc not running" would occur in production.
|
||||||
*/
|
*/
|
||||||
import { describe, expect, it, vi, beforeEach, afterEach } from "vitest";
|
import { describe, expect, it, vi, beforeEach, afterEach } from "vitest";
|
||||||
|
import {
|
||||||
|
clearAllDispatchers,
|
||||||
|
getTotalPendingReplies,
|
||||||
|
} from "../auto-reply/reply/dispatcher-registry.js";
|
||||||
|
import { createReplyDispatcher } from "../auto-reply/reply/reply-dispatcher.js";
|
||||||
|
|
||||||
function createDeferred<T = void>() {
|
function createDeferred<T = void>() {
|
||||||
let resolve!: (value: T | PromiseLike<T>) => void;
|
let resolve!: (value: T | PromiseLike<T>) => void;
|
||||||
@@ -26,14 +31,10 @@ describe("real scenario: config change during message processing", () => {
|
|||||||
vi.restoreAllMocks();
|
vi.restoreAllMocks();
|
||||||
// Wait for any pending microtasks (from markComplete()) to complete
|
// Wait for any pending microtasks (from markComplete()) to complete
|
||||||
await Promise.resolve();
|
await Promise.resolve();
|
||||||
const { clearAllDispatchers } = await import("../auto-reply/reply/dispatcher-registry.js");
|
|
||||||
clearAllDispatchers();
|
clearAllDispatchers();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should NOT restart gateway while reply delivery is in flight", async () => {
|
it("should NOT restart gateway while reply delivery is in flight", async () => {
|
||||||
const { createReplyDispatcher } = await import("../auto-reply/reply/reply-dispatcher.js");
|
|
||||||
const { getTotalPendingReplies } = await import("../auto-reply/reply/dispatcher-registry.js");
|
|
||||||
|
|
||||||
let rpcConnected = true;
|
let rpcConnected = true;
|
||||||
const deliveredReplies: string[] = [];
|
const deliveredReplies: string[] = [];
|
||||||
const deliveryStarted = createDeferred();
|
const deliveryStarted = createDeferred();
|
||||||
@@ -95,8 +96,6 @@ describe("real scenario: config change during message processing", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should keep pending > 0 until reply is actually enqueued", async () => {
|
it("should keep pending > 0 until reply is actually enqueued", async () => {
|
||||||
const { createReplyDispatcher } = await import("../auto-reply/reply/reply-dispatcher.js");
|
|
||||||
const { getTotalPendingReplies } = await import("../auto-reply/reply/dispatcher-registry.js");
|
|
||||||
const allowDelivery = createDeferred();
|
const allowDelivery = createDeferred();
|
||||||
|
|
||||||
const dispatcher = createReplyDispatcher({
|
const dispatcher = createReplyDispatcher({
|
||||||
|
|||||||
Reference in New Issue
Block a user