|
| 1 | +Test that dune fails fast when the build lock is held but no RPC server is |
| 2 | +available. This is a regression test for |
| 3 | +https://github.com/ocaml/dune/issues/12900 |
| 4 | + |
| 5 | + $ cat > dune-project <<EOF |
| 6 | + > (lang dune 3.18) |
| 7 | + > EOF |
| 8 | + |
| 9 | + $ cat > dune <<EOF |
| 10 | + > (executable (name foo)) |
| 11 | + > EOF |
| 12 | + |
| 13 | + $ cat > foo.ml <<EOF |
| 14 | + > let () = print_endline "hello" |
| 15 | + > EOF |
| 16 | + |
| 17 | +Helper to run a command while holding the build lock without an RPC server: |
| 18 | + |
| 19 | + $ with_build_lock_held() { |
| 20 | + > mkdir -p _build |
| 21 | + > ( |
| 22 | + > flock -x 9 |
| 23 | + > printf '%s' $$ > _build/.lock |
| 24 | + > "$@" 2>&1 | sed 's/pid: [0-9]*/pid: PID/' |
| 25 | + > ) 9>_build/.lock |
| 26 | + > } |
| 27 | + |
| 28 | +Hold the lock without running an RPC server, then try various commands. |
| 29 | +They should all fail immediately instead of hanging. |
| 30 | + |
| 31 | + $ with_build_lock_held dune build |
| 32 | + Error: Another dune instance (pid: PID) has the build directory locked |
| 33 | + but is not running an RPC server. |
| 34 | + |
| 35 | + $ with_build_lock_held dune exec ./foo.exe |
| 36 | + Error: Another dune instance (pid: PID) has the build directory locked |
| 37 | + but is not running an RPC server. |
| 38 | + |
| 39 | + $ with_build_lock_held dune fmt |
| 40 | + Error: Another dune instance (pid: PID) has the build directory locked |
| 41 | + but is not running an RPC server. |
| 42 | + |
| 43 | + $ with_build_lock_held dune promote |
| 44 | + Error: Another dune instance (pid: PID) has the build directory locked |
| 45 | + but is not running an RPC server. |
| 46 | + |
| 47 | + $ with_build_lock_held dune runtest |
| 48 | + Error: Another dune instance (pid: PID) has the build directory locked |
| 49 | + but is not running an RPC server. |
| 50 | + |
| 51 | +We are not starting an RPC server for clean, but we do care if the lock is |
| 52 | +held. |
| 53 | + |
| 54 | + $ with_build_lock_held dune clean |
| 55 | + Error: A running dune (pid: PID) instance has locked the build directory. |
| 56 | + If this is not the case, please delete "_build/.lock". |
| 57 | + |
| 58 | +Explicit RPC commands do not check the lock first, so they get a simpler error: |
| 59 | + |
| 60 | + $ dune rpc ping |
| 61 | + Error: RPC server not running. |
| 62 | + [1] |
| 63 | + |
| 64 | + $ dune rpc build |
| 65 | + Error: RPC server not running. |
| 66 | + [1] |
| 67 | + |
| 68 | + $ dune shutdown |
| 69 | + Error: RPC server not running. |
| 70 | + [1] |
| 71 | + |
| 72 | + $ dune diagnostics |
| 73 | + Error: RPC server not running. |
| 74 | + [1] |
| 75 | + |
| 76 | +Commands that start their own RPC server will fail when trying to acquire the |
| 77 | +lock: |
| 78 | + |
| 79 | + $ with_build_lock_held dune utop . 2>&1 | head -3 |
| 80 | + Error: A running dune (pid: PID) instance has locked the build directory. |
| 81 | + If this is not the case, please delete "_build/.lock". |
| 82 | + |
| 83 | + $ with_build_lock_held dune ocaml top 2>&1 | head -3 |
| 84 | + Error: A running dune (pid: PID) instance has locked the build directory. |
| 85 | + If this is not the case, please delete "_build/.lock". |
| 86 | + |
| 87 | + $ with_build_lock_held dune printenv 2>&1 | head -3 |
| 88 | + Error: A running dune (pid: PID) instance has locked the build directory. |
| 89 | + If this is not the case, please delete "_build/.lock". |
| 90 | + |
| 91 | + $ with_build_lock_held dune describe workspace 2>&1 | head -3 |
| 92 | + Error: A running dune (pid: PID) instance has locked the build directory. |
| 93 | + If this is not the case, please delete "_build/.lock". |
| 94 | + |
0 commit comments