codebaobab
Python workspace

FDE interview labData & Systems

Scheduler Under Test

Write tests that pin a job scheduler to its contract and fix what they find.

Python50 minutesData & Systems

Challenge brief

Read before you begin

Your mission · Test writing

Write a test suite that catches a broken payroll scheduler, and fix what it finds.

Fernhill Payroll's nightly scheduler locked the company out of its bank and then stopped on a false stuck error, which forced an on-call fix at 04:30. The incident review found almost no tests guarding it. Year-end payroll and W-2 runs begin December 15, and changes must stay safe.

  • Target · 6 builds caught
  • Mode · Test writing
Skip to round setup

Your assignment

  1. Turn each contract rule into at least one test.
  2. Make the suite fail on all six broken builds.
  3. Fix the scheduler where a contract test fails.
  4. Handle the new requirement when it arrives.
  5. Map each test to its rule in NOTES.md.

The problem

The bank locked the account

The bank upload was tried five times; the bank locks after four failed logins.

Impact: The account stayed locked until morning.

The run stopped as stuck

The run raised "stuck" instead of finishing the jobs that could still run.

Impact: On-call cleared it by hand at 04:30.

Three tests guard everything

Retries, backoff, priority and skipping have no test.

Impact: All six broken builds pass the current suite.

Context

Tests on the scheduler
3
Bank upload attempts
5
Year-end payroll starts
Dec 15

Requirements

  • Highest priority first, ties in the order added.
  • At most 1 + max_retries runs per job.
  • Retry n waits base_delay * 2^(n - 1).
  • Skip jobs with a failed or skipped dependency.
  • run_until_idle() moves the clock to the next retry.
  • add() rejects duplicates and unknown dependencies.
  • Tests use the fake clock and docs/contract.md.

System overview

Edit the components marked “Your work”. The other components show where your changes fit.

Nightly triggerStarts the nightly run
Job graphJobs and dependencies
Scheduler(Your work)Orders and runs jobs
Test suiteTests the scheduler
Payroll workersRun payroll jobs
Bank SFTPTakes deposit files
Read the connections
  • Nightly trigger → Scheduler: start run
  • Job graph → Scheduler: jobs
  • Scheduler → Payroll workers: tick: run jobs
  • Payroll workers → Bank SFTP: upload
  • Test suite → Scheduler: pins contract
  • Nightly trigger: Starts the run at 01:00 Eastern with the job graph.
  • Job graph: About 1,400 jobs: retries, priority and depends_on for each.
  • Scheduler: Job in scheduler/domain/jobs.py, Scheduler in scheduler/services/engine.py, FakeClock in scheduler/services/clock.py. Checks call handle in scheduler/core.py.
  • Test suite: test_ functions in scheduler/testing/checks.py, run against every build.
  • Payroll workers: Run each job: compute, bank upload, payslip email.
  • Bank SFTP: Takes the deposit file. Locks after 4 failed logins.

Data model

Job

FieldTypeNotes
idstringUnique in the graph.
statestringwaiting, done, failed or skipped.
max_retries, priorityintegerRetries after the first run; higher priority runs first.
depends_ontuple of idsAdded before this job.
runs, retries, ready_atintegerCalls so far, retries given, earliest time of the next run.

Run request and result

FieldTypeNotes
jobs[{id, fails, max_retries, priority, depends_on}]fails is a count of failing runs, or "always".
stepslist"tick", "idle" or {advance: seconds}. Missing means run until idle.
result{states, runs, log, time}log is [time, job id, "ok" or "fail"] per run.

Details

Full requirements

Functional

  1. tick() runs every job that can start now, once each, highest priority first, ties in the order added. Payroll for a country must start before the audit snapshot that only reads it.
  2. A job is retried at most max_retries times, so it runs at most 1 + max_retries times. The bank upload has max_retries 3 because the bank locks after four failures.
  3. Retry number n waits base_delay * 2^(n - 1) seconds after the failure before it: 2, 4, 8 with base_delay 2.
  4. A job with a failed or skipped dependency is skipped and never runs, directly or indirectly. run_until_idle() ticks until nothing is waiting, moving the clock to the next retry time when nothing can run now.
  5. add() rejects a duplicate id and a dependency that was not added first, so a bad job graph fails at load time, not at 03:00.
  6. Your suite passes on the scheduler and fails on each of the six broken builds. Tests use the fake clock, and every expected value comes from docs/contract.md.

Non-functional

  • Scale: about 1,400 jobs a night, up to 300 of them ready in the same tick after the timesheet pull. The run must finish by 06:00 Eastern, when deposits are due at the bank.
  • Test speed: all the checks share one 30-second run. With a fake clock a test of a 14-second backoff takes microseconds; with real sleeps the suite would never fit.
  • Determinism: the scheduler is single threaded and nothing happens between ticks, so the same graph and the same failures always give the same log.
  • External limits: the bank allows 4 failed logins per account per night; the payslip mailer allows 50,000 emails an hour.

Out of scope

  • The workers and what each job does: tests use the succeed, fail and fail_times fixtures.
  • Persisting job state across restarts, and running the scheduler on more than one machine.
  • Editing the broken builds, or a test that checks which build it runs on: a test must fail because of what the build does.
Files you are given · 4
  • samples/requests-nightly.json Three run requests for handle: the bank upload failing every time, a failed upload with two jobs downstream, and a timesheet pull that fails once ahead of two priority-5 jobs.
    [
      {
        "op": "run",
        "base_delay": 2,
        "jobs": [
          {
            "id": "upload-bank-file",
            "fails": "always",
            "max_retries": 3
          }
        ]
      },
      {
        "op": "run",
        "jobs": [
          {
            "id": "upload-bank-file",
            "fails": "always"
          },
          {
            "id": "confirm-deposits",
            "depends_on": [
              "upload-bank-file"
            ]
          },
          {
            "id": "email-payslips",
            "depends_on": [
              "confirm-deposits"
            ]
          }
        ]
      },
      {
        "op": "run",
        "jobs": [
          {
            "id": "pull-timesheets",
            "fails": 1,
            "max_retries": 2
          },
          {
            "id": "compute-payroll-us",
            "depends_on": [
              "pull-timesheets"
            ],
            "priority": 5
          },
          {
            "id": "audit-snapshot",
            "priority": 1
          },
          {
            "id": "compute-payroll-ca",
            "depends_on": [
              "pull-timesheets"
            ],
            "priority": 5
          }
        ]
      }
    ]
  • samples/expected-nightly.json What the contract says each request returns, in the same order. Every value can be traced to a numbered rule.
    [
      {
        "states": {
          "upload-bank-file": "failed"
        },
        "runs": {
          "upload-bank-file": 4
        },
        "log": [
          [
            0,
            "upload-bank-file",
            "fail"
          ],
          [
            2,
            "upload-bank-file",
            "fail"
          ],
          [
            6,
            "upload-bank-file",
            "fail"
          ],
          [
            14,
            "upload-bank-file",
            "fail"
          ]
        ],
        "time": 14
      },
      {
        "states": {
          "upload-bank-file": "failed",
          "confirm-deposits": "skipped",
          "email-payslips": "skipped"
        },
        "runs": {
          "upload-bank-file": 1,
          "confirm-deposits": 0,
          "email-payslips": 0
        },
        "log": [
          [
            0,
            "upload-bank-file",
            "fail"
          ]
        ],
        "time": 0
      },
      {
        "states": {
          "pull-timesheets": "done",
          "compute-payroll-us": "done",
          "audit-snapshot": "done",
          "compute-payroll-ca": "done"
        },
        "runs": {
          "pull-timesheets": 2,
          "compute-payroll-us": 1,
          "audit-snapshot": 1,
          "compute-payroll-ca": 1
        },
        "log": [
          [
            0,
            "audit-snapshot",
            "ok"
          ],
          [
            0,
            "pull-timesheets",
            "fail"
          ],
          [
            2,
            "pull-timesheets",
            "ok"
          ],
          [
            2,
            "compute-payroll-us",
            "ok"
          ],
          [
            2,
            "compute-payroll-ca",
            "ok"
          ]
        ],
        "time": 2
      }
    ]
  • config/nightly-jobs.yaml The part of the production job graph these samples come from, with the retry limit the bank imposes.
    # Part of the November job graph. base_delay is 2 seconds in tests; production uses 30.
    base_delay_seconds: 30
    jobs:
      - id: pull-timesheets
        max_retries: 2
      - id: audit-snapshot
        priority: 1
      - id: compute-payroll-us
        priority: 5
        depends_on: [pull-timesheets]
      - id: compute-payroll-ca
        priority: 5
        depends_on: [pull-timesheets]
      - id: upload-bank-file
        max_retries: 3   # the bank locks the account after 4 failed logins
        depends_on: [compute-payroll-us, compute-payroll-ca]
      - id: confirm-deposits
        depends_on: [upload-bank-file]
      - id: email-payslips
        depends_on: [confirm-deposits]
  • logs/nightly-2026-11-14.log The incident night: five attempts against the bank, then the run stopping with "stuck" until on-call cleared it.
    2026-11-14T01:52:10Z scheduler run job=upload-bank-file attempt=1 result=fail reason="sftp: connection reset"
    2026-11-14T01:52:40Z scheduler run job=upload-bank-file attempt=2 result=fail reason="sftp: connection reset"
    2026-11-14T01:53:40Z scheduler run job=upload-bank-file attempt=3 result=fail reason="sftp: connection reset"
    2026-11-14T01:55:40Z scheduler run job=upload-bank-file attempt=4 result=fail reason="sftp: auth failed"
    2026-11-14T01:59:40Z scheduler run job=upload-bank-file attempt=5 result=fail reason="sftp: account locked"
    2026-11-14T02:10:41Z scheduler error RuntimeError: stuck: jobs are waiting and nothing can ever run waiting=212
    2026-11-14T04:30:02Z oncall action=manual-clear run=nightly-2026-11-14 by=k.mensah
Tickets · 3
  • TASK-201 Turn each contract rule into at least one test Reported by Rachel (Batch Platform lead)

    Expected At least one test_ function per numbered rule, with expected values written from the rule.

    Actual The report shows 3 tests: one job runs, one job without retries fails, one dependent job runs. Retries, backoff, priority and skipping have no test.

  • TASK-202 Make the suite fail on every broken build Reported by Rachel (Batch Platform lead)

    Expected suite is "fail" on all six broken builds and "pass" on "scheduler".

    Actual suite is "pass" on all six broken builds, so every "Suite: fails on ..." check fails.

  • TASK-203 When a contract test fails on the scheduler, fix the scheduler Reported by Kofi (on-call, Nov 14)

    Expected The bank upload runs 4 times, at 0, 2, 6 and 14 seconds. In the chain, confirm-deposits and email-payslips are skipped and the run ends at time 0.

    Actual The bank upload runs 5 times, the last at 30 seconds. The chain raises RuntimeError "stuck: jobs are waiting and nothing can ever run".

What you hand in
  • A suite that passes on the scheduler and fails on all six broken builds, and the scheduler fixes your tests proved necessary.
  • NOTES.md: for each test, the rule it pins; for each scheduler fix, the test that found it.
  • Your answer to the interviewer's follow-up and the debrief questions.
How the work is judged
Breaking down the work
Lists the rules the three tests leave open before writing any, then adds one test per rule and runs the checks after each.
Directing the assistant
Asks the assistant for a test of one named rule with the expected value from the contract, not for "more tests".
Checking the work
Uses report to see which builds each test catches, and disable to prove a test exercises the method it claims to.
Judging the assistant
Rejects a test whose expected value was copied from the output, and fixes the scheduler, not the test, when a contract test fails on it.
Correct result
The suite passes on the scheduler and fails on every broken build, and the scheduler meets rules 6 and 8.
Explaining the work
Explains why two builds could not be caught until the scheduler was fixed, in terms of the bank lockout and the stuck run.
Trade-offs to discuss
  • Tests that pin the contract versus tests that pin today's behavior, and how each ages when the scheduler changes.
  • How many tests per rule: one sharp case, or the edges (0 retries, 1, many).
  • Whether a stuck run should raise, skip what cannot run, or page on-call, when payroll has a 06:00 deadline.
How you are graded
  • Decomposition 15%
  • Prompting the assistant 15%
  • Verification 20%
  • Judgment about AI output 15%
  • Correctness 25%
  • Communication 10%

Scores use evidence from your session. A short or incomplete session may not provide enough evidence for every skill. See a sample scorecard

Interview guidance

This job scheduler has three shallow tests and a written contract. The same file has six broken builds, and each breaks one rule. Write tests that pass on the scheduler and fail on every broken build, and fix whatever your tests find. Use the AI assistant however you like. Start by telling me which contract rules the three existing tests leave open.

  • AI is allowed and expected: your own Claude, OpenAI or Gemini key, or the free in-browser model.
  • You are graded on how you drive and check the AI, not on how much you prompt.
  • Run the checks; read what fails.
  • A new requirement will arrive partway through.
  • Too little AI use is reported as “not enough to grade”, never as a fail.
Debrief · 7 questions
  • What did you delegate to the AI, and why?
  • Name one AI suggestion you rejected or changed, and why.
  • Choose one block the AI helped write. Explain what each line does and which test verifies it.
  • What is still risky, and what would you test or ship next?
  • Which test first failed on the scheduler itself, and how did you decide whether the test or the scheduler was wrong?
  • Pick one test the assistant wrote that you changed or threw away. What was wrong with it?
  • What does your suite still not cover, and which broken build would you add next to prove it?