#Testing OCC Improvements
4 messages · Page 1 of 1 (latest)
Hi @storm yoke. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
You’re right that convex-test won’t help here: it’s a single-process mock and explicitly doesn’t model real OCC behavior or limits. [convex-test limits]
From the docs and Stack posts, there are two reliable ways to actually see OCC conflicts and measure improvements:
1. Use patterns that are known to conflict
Convex documents several “bad” patterns that reliably trigger OCC conflicts when driven with enough parallelism:
-
A mutation that always reads and writes the same document (singleton counter): [Errors OCC]
export const updateCounter = mutation({ args: {}, handler: async (ctx) => { const doc = await ctx.db.get("counts", process.env.COUNTER_ID!); await ctx.db.patch(doc!._id, { value: doc!.value + 1 }); }, });Calling this many times per second in parallel will produce OCC errors.
-
A mutation that depends on a whole table or large index range, while another mutation writes into that range (e.g.
writeCount+addTask): [Errors OCC]
These are good “stress tests” for OCC: you can hammer them with concurrent calls and then try improved designs (sharding, narrower queries, queue pattern, aggregates, Workpool, etc.) and compare error rates and throughput.
2. Run against a real backend (local OSS or cloud), not convex-test
To actually exercise OCC and measure improvements, you need the real Convex backend:
- The local open‑source backend is explicitly recommended for tests that should behave like production, including limits and concurrency. [Testing local backend]
convex-testis positioned only for logic tests; it does not model OCC or many backend behaviors. [convex-test limits]
So for reproducible OCC conflicts:
- Stand up the local backend (per the testing guide). [Testing local backend]
- Implement one of the known-conflict patterns above.
- Drive high parallelism from a load script or test runner (multiple concurrent mutation calls).
- Observe:
- OCC errors in logs / client
- Throughput and latency
- Apply your “improvement” (e.g. sharding, queue pattern, Workpool with
maxParallelism: 1to serialize a hot mutation) and repeat to compare. [Queue pattern; Workpool OCC]