Initial import of streamline
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
import "./setup_env";
|
||||
import { test, expect } from "bun:test";
|
||||
import { PgDialect } from "drizzle-orm/pg-core";
|
||||
import { claimWhere } from "../src/db";
|
||||
import { tasks } from "../src/db_client";
|
||||
import { dispatchableTo, isManualOnlyNode, MANUAL_ONLY_CLUSTER } from "@bbbug/shared/types";
|
||||
|
||||
// 渲染成 SQL 文本来断言 —— 单测不开数据库。
|
||||
const render = (nc: string[], steal = false) => {
|
||||
const q = new PgDialect().sqlToQuery(claimWhere(tasks, "awaiting_fix", "ios", "temp-ios-01", [], nc, { steal }));
|
||||
return { sql: q.sql, params: q.params };
|
||||
};
|
||||
|
||||
test("实验机:只认绑给自己的项,不接无主单、不偷单、不比集群", () => {
|
||||
for (const steal of [false, true]) {
|
||||
const { sql, params } = render([MANUAL_ONLY_CLUSTER], steal);
|
||||
expect(sql).not.toContain("\"executor_node_id\" is null"); // 无主的单不接
|
||||
expect(sql).not.toContain("json_array_elements_text"); // 不比集群
|
||||
expect(sql).not.toContain("<>"); // 不偷别的节点的单
|
||||
expect(params).toContain("temp-ios-01");
|
||||
}
|
||||
// 混着别的标签也一样:带上保留标签就是实验机。
|
||||
expect(render(["default", MANUAL_ONLY_CLUSTER], true).sql).not.toContain("\"executor_node_id\" is null");
|
||||
});
|
||||
|
||||
test("普通节点的接单条件不变", () => {
|
||||
const { sql } = render(["default"]);
|
||||
expect(sql).toContain("\"executor_node_id\" is null");
|
||||
expect(sql).toContain("json_array_elements_text");
|
||||
});
|
||||
|
||||
test("调度台:实验机不比集群,普通节点照旧", () => {
|
||||
expect(isManualOnlyNode([MANUAL_ONLY_CLUSTER])).toBe(true);
|
||||
expect(isManualOnlyNode(["default"])).toBe(false);
|
||||
expect(dispatchableTo([MANUAL_ONLY_CLUSTER], { clusters: [] })).toBe(true);
|
||||
expect(dispatchableTo([MANUAL_ONLY_CLUSTER], { clusters: ["pns"] })).toBe(true);
|
||||
expect(dispatchableTo(["default"], { clusters: ["pns"] })).toBe(false);
|
||||
expect(dispatchableTo(["default"], { clusters: [] })).toBe(true);
|
||||
});
|
||||
|
||||
test("执行过的单回原节点不比集群:节点改标签后不再死锁", () => {
|
||||
// 普通节点:集群条件之外多一条「绑给自己且执行过」的豁免。
|
||||
const { sql, params } = render(["evaluator"]);
|
||||
expect(sql).toContain("json_array_elements_text");
|
||||
expect(sql).toMatch(/"executor_node_id" = \$\d+ and "tasks"\."attempts" > \$\d+/);
|
||||
expect(params).toContain("temp-ios-01");
|
||||
// 停放的节点(零集群)仍然什么都不接。
|
||||
expect(render([]).sql).toContain("false");
|
||||
});
|
||||
Reference in New Issue
Block a user