snapshot of https://github.com/zulip/zulip.git @ 48c69911c7dd4e03b20552eb3bd77ad8151c1357 (2026-09-15)
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
This commit is contained in:
123
web/tests/lib/zblueslip.cjs
Normal file
123
web/tests/lib/zblueslip.cjs
Normal file
@@ -0,0 +1,123 @@
|
||||
"use strict";
|
||||
|
||||
const assert = require("node:assert/strict");
|
||||
|
||||
function make_zblueslip() {
|
||||
const lib = {};
|
||||
|
||||
const opts = {
|
||||
// Silently swallow all debug, log and info calls.
|
||||
debug: false,
|
||||
log: false,
|
||||
info: false,
|
||||
// Check against expected error values for the following.
|
||||
warn: true,
|
||||
error: true,
|
||||
};
|
||||
const names = Object.keys(opts);
|
||||
|
||||
// For fatal messages, we should use assert.throws
|
||||
/* istanbul ignore next */
|
||||
lib.fatal = (msg) => {
|
||||
throw new Error(msg);
|
||||
};
|
||||
|
||||
// Store valid test data for options.
|
||||
lib.test_data = {};
|
||||
lib.test_logs = {};
|
||||
|
||||
for (const name of names) {
|
||||
lib.test_data[name] = [];
|
||||
lib.test_logs[name] = [];
|
||||
}
|
||||
|
||||
lib.expect = (name, message, expected_count = 1) => {
|
||||
assert.notEqual(opts[name], undefined, `unexpected arg for expect: ${name}`);
|
||||
assert.ok(
|
||||
expected_count > 0 && Number.isSafeInteger(expected_count),
|
||||
"expected count should be a positive integer",
|
||||
);
|
||||
const obj = {message, count: 0, expected_count};
|
||||
lib.test_data[name].push(obj);
|
||||
};
|
||||
|
||||
const check_seen_messages = () => {
|
||||
for (const name of names) {
|
||||
const logs = lib.test_logs[name];
|
||||
const data = lib.test_data[name];
|
||||
for (const obj of logs) {
|
||||
const message = obj.message;
|
||||
const i = data.findIndex((x) => x.message === message);
|
||||
if (i === -1) {
|
||||
// Only throw this for message types we want to explicitly track.
|
||||
// For example, we do not want to throw here for debug messages.
|
||||
if (opts[name] ?? false) {
|
||||
throw new Error(`Unexpected '${name}' message: ${message}`);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
data[i].count += 1;
|
||||
}
|
||||
|
||||
for (const obj of data) {
|
||||
const message = obj.message;
|
||||
assert.equal(
|
||||
obj.count,
|
||||
obj.expected_count,
|
||||
`Expected ${obj.expected_count} of '${name}': ${message}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
lib.reset = (skip_checks = false) => {
|
||||
if (!skip_checks) {
|
||||
check_seen_messages();
|
||||
}
|
||||
|
||||
for (const name of names) {
|
||||
lib.test_data[name] = [];
|
||||
lib.test_logs[name] = [];
|
||||
}
|
||||
};
|
||||
|
||||
lib.get_test_logs = (name) => lib.test_logs[name];
|
||||
|
||||
// Create logging functions
|
||||
for (const name of names) {
|
||||
if (!(opts[name] ?? false)) {
|
||||
// should just log the message.
|
||||
lib[name] = function (message, more_info, cause) {
|
||||
lib.test_logs[name].push({message, more_info, cause});
|
||||
};
|
||||
continue;
|
||||
}
|
||||
lib[name] = function (message, more_info, cause) {
|
||||
/* istanbul ignore if */
|
||||
if (typeof message !== "string") {
|
||||
// We may catch exceptions in blueslip, and if
|
||||
// so our stub should include that.
|
||||
if (message.toString().includes("exception")) {
|
||||
message = message.toString();
|
||||
} else {
|
||||
throw new Error("message should be string: " + message);
|
||||
}
|
||||
}
|
||||
lib.test_logs[name].push({message, more_info, cause});
|
||||
const matched_error_message = lib.test_data[name].some((x) => x.message === message);
|
||||
const exact_match_fail = !matched_error_message;
|
||||
if (exact_match_fail) {
|
||||
const error = new Error(
|
||||
`Invalid ${name} message: "${message}".`,
|
||||
cause === undefined ? {} : {cause},
|
||||
);
|
||||
error.blueslip = true;
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return lib;
|
||||
}
|
||||
|
||||
module.exports = make_zblueslip();
|
||||
Reference in New Issue
Block a user