Skip to content

Commit 860bff1

Browse files
committed
Reproduce bounded mysqli_poll timeout
1 parent 3def924 commit 860bff1

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

tests/disposable-mysql-mysqli.integration.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,21 @@ if (!await dockerAvailable()) {
4545
assert.equal(result.success, true, JSON.stringify(result))
4646
assert.equal(result.executions.at(-1)?.stdout.trim(), "1")
4747

48+
const mysqliPollRecipePath = join(directory, "mysqli-poll-recipe.json")
49+
const mysqliPollCode = "mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); $first = mysqli_init(); $second = mysqli_init(); mysqli_real_connect($first, getenv('DB_HOST'), 'root', '', 'runtime', (int) getenv('DB_PORT')); mysqli_real_connect($second, getenv('DB_HOST'), 'root', '', 'runtime', (int) getenv('DB_PORT')); $first->query('CREATE TABLE poll_lock (id INT PRIMARY KEY) ENGINE=InnoDB'); $first->query('INSERT INTO poll_lock VALUES (1)'); $first->query('START TRANSACTION'); $first->query('SELECT id FROM poll_lock WHERE id = 1 FOR UPDATE'); $second->query('START TRANSACTION'); $second->query('SELECT id FROM poll_lock WHERE id = 1 FOR UPDATE', MYSQLI_ASYNC); $read = [$second]; $error = []; $reject = []; $started = microtime(true); $ready = mysqli_poll($read, $error, $reject, 0, 100000); echo json_encode(['ready' => $ready, 'elapsed_ms' => round((microtime(true) - $started) * 1000)]); $first->query('ROLLBACK'); $second->query('ROLLBACK');"
50+
await writeFile(mysqliPollRecipePath, JSON.stringify({
51+
schema: "wp-codebox/workspace-recipe/v1",
52+
inputs: {
53+
services: [{ id: "mysql", kind: "mysql", configuration: { rootAuthentication: "empty-password" }, outputs: { host: "DB_HOST", port: "DB_PORT" } }],
54+
},
55+
workflow: { steps: [{ command: "wordpress.run-php", args: [`code=${mysqliPollCode}`] }] },
56+
}))
57+
const mysqliPollResult = await runRecipe({ recipePath: mysqliPollRecipePath, previewHoldBlocking: false, previewLeaseRequested: false, previewLeaseChild: false, timeoutMs: 20_000, json: true, summary: false, dryRun: false })
58+
assert.equal(mysqliPollResult.success, true, JSON.stringify(mysqliPollResult))
59+
const mysqliPollOutput = JSON.parse(mysqliPollResult.executions.at(-1)?.stdout ?? "{}")
60+
assert.equal(mysqliPollOutput.ready, 0)
61+
assert.ok(mysqliPollOutput.elapsed_ms >= 50 && mysqliPollOutput.elapsed_ms < 1_000, JSON.stringify(mysqliPollOutput))
62+
4863
const mariaDbRecipePath = join(directory, "mariadb-recipe.json")
4964
const mariaDbCode = "if (!function_exists('mysqli_init')) { throw new RuntimeException('mysqli is unavailable'); } $db = mysqli_init(); if (!mysqli_real_connect($db, getenv('DB_HOST'), 'root', '', 'runtime', (int) getenv('DB_PORT'))) { throw new RuntimeException(mysqli_connect_error()); } mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); mysqli_query($db, 'CREATE TABLE parent (id INT NOT NULL, KEY (id)) ENGINE=InnoDB'); mysqli_query($db, 'CREATE TABLE child (parent_id INT NOT NULL, FOREIGN KEY (parent_id) REFERENCES parent(id)) ENGINE=InnoDB'); mysqli_query($db, \"CREATE TABLE settings (payload LONGTEXT NOT NULL DEFAULT '{}') ENGINE=InnoDB\"); $result = mysqli_query($db, 'SELECT 1 AS connected'); echo mysqli_fetch_assoc($result)['connected'];"
5065
await writeFile(mariaDbRecipePath, JSON.stringify({

0 commit comments

Comments
 (0)