Files
windmill/backend/tests/fixtures/schedule_push.sql
Ruben Fiszel e655a06563 fix: prevent schedule pool connection exhaustion (#7821)
* fix: prevent schedule pool connection exhaustion

Schedules were disabling themselves after upgrading from v1.605.0 to
v1.614.0 due to pool connection deadlock. The root cause was
fetch_authed_from_permissioned_as acquiring a pool connection inside
push() while a transaction already held one, exhausting the pool under
pressure.

Fix: pre-compute Authed before db.begin() for the normal path, and
reuse the transaction connection via fetch_authed_from_permissioned_as_conn
for the on_behalf_of_email path. Peak pool usage drops from 2 to 1 for
all schedule push paths.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: replace pool exhaustion tests with comprehensive schedule push tests

Replace the 16 pool-specific tests with 19 tests covering all schedule
push code paths: script/flow scheduling, on_behalf_of_email (script and
flow), retry wrapping, duplicate detection, invalid timezone/cron/args,
script/flow not found, paused schedules, clock shift detection, disabled
schedule, path mismatch, push failure disabling schedule, and trigger
metadata.

Also simplify the obo_authed pattern in push_scheduled_job to use a
single match assignment instead of two bindings with .or() chaining.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-05 23:25:42 +00:00

85 lines
4.1 KiB
SQL

-- Fixture for schedule push tests
-- Sets up scripts, flows, users, and schedules needed to test push_scheduled_job
-- Password entries for auth resolution
INSERT INTO password (email, password_hash, login_type, super_admin, verified, name)
VALUES
('test@windmill.dev', 'dummy_hash', 'password', false, true, 'Test User'),
('obo@windmill.dev', 'dummy_hash', 'password', false, true, 'OBO User')
ON CONFLICT (email) DO NOTHING;
-- OBO user in workspace
INSERT INTO usr (workspace_id, email, username, is_admin, role)
VALUES ('test-workspace', 'obo@windmill.dev', 'obo-user', false, 'Developer')
ON CONFLICT (workspace_id, username) DO NOTHING;
-- A simple script
INSERT INTO script (workspace_id, created_by, content, schema, summary, description, path, hash, language, lock, kind)
VALUES (
'test-workspace', 'test-user',
'export async function main() { return "ok"; }',
'{"$schema":"https://json-schema.org/draft/2020-12/schema","properties":{},"required":[],"type":"object"}',
'Test script', '', 'f/system/test_script', 100001, 'deno', '', 'script'
);
-- A script with on_behalf_of_email
INSERT INTO script (workspace_id, created_by, content, schema, summary, description, path, hash, language, lock, kind, on_behalf_of_email)
VALUES (
'test-workspace', 'test-user',
'export async function main() { return "obo"; }',
'{"$schema":"https://json-schema.org/draft/2020-12/schema","properties":{},"required":[],"type":"object"}',
'OBO script', '', 'f/system/obo_script', 100002, 'deno', '', 'script', 'obo@windmill.dev'
);
-- A script with a tag
INSERT INTO script (workspace_id, created_by, content, schema, summary, description, path, hash, language, lock, kind, tag)
VALUES (
'test-workspace', 'test-user',
'export async function main() { return "tagged"; }',
'{"$schema":"https://json-schema.org/draft/2020-12/schema","properties":{},"required":[],"type":"object"}',
'Tagged script', '', 'f/system/tagged_script', 100003, 'deno', '', 'script', 'custom-tag'
);
-- A script with timeout
INSERT INTO script (workspace_id, created_by, content, schema, summary, description, path, hash, language, lock, kind, timeout)
VALUES (
'test-workspace', 'test-user',
'export async function main() { return "timeout"; }',
'{"$schema":"https://json-schema.org/draft/2020-12/schema","properties":{},"required":[],"type":"object"}',
'Timeout script', '', 'f/system/timeout_script', 100004, 'deno', '', 'script', 300
);
-- A flow
INSERT INTO flow (workspace_id, summary, description, path, versions, schema, value, edited_by)
VALUES (
'test-workspace', 'Test flow', '', 'f/system/test_flow', '{200001}',
'{"$schema":"https://json-schema.org/draft/2020-12/schema","properties":{},"required":[],"type":"object"}',
'{"modules": [{"id": "a", "value": {"path": "f/system/test_script", "type": "script", "input_transforms": {}}}]}',
'test-user'
);
INSERT INTO flow_version (id, workspace_id, path, schema, value, created_by)
VALUES (
200001, 'test-workspace', 'f/system/test_flow',
'{"$schema":"https://json-schema.org/draft/2020-12/schema","properties":{},"required":[],"type":"object"}',
'{"modules": [{"id": "a", "value": {"path": "f/system/test_script", "type": "script", "input_transforms": {}}}]}',
'test-user'
);
-- A flow with on_behalf_of_email
INSERT INTO flow (workspace_id, summary, description, path, versions, schema, value, edited_by, on_behalf_of_email)
VALUES (
'test-workspace', 'OBO flow', '', 'f/system/obo_flow', '{200002}',
'{"$schema":"https://json-schema.org/draft/2020-12/schema","properties":{},"required":[],"type":"object"}',
'{"modules": [{"id": "a", "value": {"path": "f/system/test_script", "type": "script", "input_transforms": {}}}]}',
'test-user', 'obo@windmill.dev'
);
INSERT INTO flow_version (id, workspace_id, path, schema, value, created_by)
VALUES (
200002, 'test-workspace', 'f/system/obo_flow',
'{"$schema":"https://json-schema.org/draft/2020-12/schema","properties":{},"required":[],"type":"object"}',
'{"modules": [{"id": "a", "value": {"path": "f/system/test_script", "type": "script", "input_transforms": {}}}]}',
'test-user'
);