Project · Rust Programming
Project: parallel UPI settlement with full tests
The brief
A payment aggregator settles each merchant's UPI collections at the end of the day. You write a library crate that parses transaction lines, adds up successful payments per merchant on several threads (a channel collects the partial totals) and counts outcomes in an Arc<Mutex<Stats>>. Then you prove it with unit tests (including should_panic), an integration test, doc tests, cargo clippy -D warnings and cargo fmt --check.
Why it matters
Fintech and payments companies in India process crores of UPI transactions a day, and settlement code must be both fast and exactly right. Splitting work across threads safely, and backing every function with tests that a CI pipeline runs on each pull request, is what Rust teams in these companies do daily.
Skills you practise
- a library crate (src/lib.rs) with a thin main.rs
- thread::spawn with move closures
- mpsc channels and dropping the sender
- Arc<Mutex<T>> shared state
- #[test], assert_eq! and #[should_panic]
- integration tests in tests/
- doc tests in /// comments
- cargo clippy -- -D warnings and cargo fmt --check
You need
- Rust stable installed with rustup, with the clippy and rustfmt components (rustup component add clippy rustfmt)
- A terminal and an editor
What you will have at the end
An upi_settle crate: a library with threaded settlement and shared counters, a thin main.rs, six unit tests, an integration test, two doc tests, and a clean cargo fmt --check and cargo clippy -D warnings run.
How it is marked (rubric, 100 points)
| Correct and deterministicTotals of Rs 95.00, Rs 680.50 and Rs 300.00, 9 successes and 2 failures, the same on every run and with any number of threads. | 30 |
|---|---|
| Safe concurrencyThe extra sender is dropped so the receiving loop ends, Arc<Mutex> holds the shared counters, and every thread is joined before results are read. | 25 |
| Tests at every levelUnit tests with edge cases and should_panic, an integration test through the public API, and doc examples that run. | 30 |
| Professional finishcargo fmt --check and cargo clippy --all-targets -- -D warnings both clean. | 15 |
0/7 steps done
Step 1 of 7
A library crate with tested parsing
parse_txn works and three unit tests pass.
Run cargo new upi_settle, then add src/lib.rs next to main.rs: a package can hold a library and a binary, and main.rs uses the library by its name (upi_settle::...). Keeping the logic in the library makes it testable without a terminal. Write parse_txn: split the line on commas, return TxnError::WrongFieldCount unless there are 4 parts, parse the amount (BadAmount on failure), and match the status text (BadStatus for anything but SUCCESS or FAILED). Then write three tests in the tests module: parses_valid_line, rejects_bad_amount and rejects_unknown_status. Run only the library's unit tests with cargo test --lib. Leave tests/settlement.rs for step 5: it uses items you have not written yet.
$ cargo test --libYour notes: src/lib.rs, src/main.rs, tests/settlement.rs
Write down each command you ran. It goes into your project summary.