|
| 1 | +#!/usr/bin/env bats |
| 2 | + |
| 3 | +load helpers |
| 4 | + |
| 5 | +# start_server launches the json-rpc-server in the background, fully |
| 6 | +# detached from bats file descriptors so it won't block test output. |
| 7 | +# Sets SERVER_PID to the actual binary PID. |
| 8 | +start_server() { |
| 9 | + local extra_args=("$@") |
| 10 | + ${STORAGE_BINARY} --graph ${TESTDIR}/root --run ${TESTDIR}/runroot \ |
| 11 | + --storage-driver ${STORAGE_DRIVER} \ |
| 12 | + ${STORAGE_OPTION:+--storage-opt=${STORAGE_OPTION}} \ |
| 13 | + json-rpc-server "${extra_args[@]}" \ |
| 14 | + </dev/null >/dev/null 2>&1 3>&- 4>&- 5>&- 6>&- 7>&- 8>&- 9>&- & |
| 15 | + SERVER_PID=$! |
| 16 | +} |
| 17 | + |
| 18 | +# stop_server kills the json-rpc-server and waits for it to exit. |
| 19 | +stop_server() { |
| 20 | + if [[ -n "$SERVER_PID" ]]; then |
| 21 | + kill "$SERVER_PID" 2>/dev/null || true |
| 22 | + wait "$SERVER_PID" 2>/dev/null || true |
| 23 | + SERVER_PID= |
| 24 | + fi |
| 25 | +} |
| 26 | + |
| 27 | +# Override teardown to stop the server before the default teardown runs |
| 28 | +# storage wipe. If the server is still running it holds the store lock |
| 29 | +# and wipe would deadlock. |
| 30 | +teardown() { |
| 31 | + stop_server |
| 32 | + run storage wipe |
| 33 | + if [[ $status -ne 0 ]] ; then |
| 34 | + echo "$output" |
| 35 | + fi |
| 36 | + run storage shutdown |
| 37 | + if [[ $status -ne 0 ]] ; then |
| 38 | + echo "$output" |
| 39 | + fi |
| 40 | + rm -fr ${TESTDIR} |
| 41 | +} |
| 42 | + |
| 43 | +@test "splitfdstream json-rpc-server and apply-splitfdstream" { |
| 44 | + case "$STORAGE_DRIVER" in |
| 45 | + overlay*) |
| 46 | + ;; |
| 47 | + *) |
| 48 | + skip "driver $STORAGE_DRIVER does not support splitfdstream" |
| 49 | + ;; |
| 50 | + esac |
| 51 | + |
| 52 | + # Create and populate a test layer |
| 53 | + populate |
| 54 | + |
| 55 | + # Get the socket path from runroot |
| 56 | + local runroot=`storage status 2>&1 | awk '/^Run Root:/{print $3}'` |
| 57 | + local socket_path="$runroot/json-rpc.sock" |
| 58 | + |
| 59 | + # Start the JSON-RPC server in the background |
| 60 | + start_server --socket "$socket_path" |
| 61 | + |
| 62 | + # Wait for socket to be created (max 10 seconds) |
| 63 | + local count=0 |
| 64 | + while [[ ! -S "$socket_path" && $count -lt 50 ]]; do |
| 65 | + sleep 0.2 |
| 66 | + count=$((count + 1)) |
| 67 | + done |
| 68 | + |
| 69 | + # Check that the socket exists |
| 70 | + [ -S "$socket_path" ] |
| 71 | + |
| 72 | + # Create a new layer using apply-splitfdstream |
| 73 | + # This should connect to our JSON-RPC server and fetch the layer |
| 74 | + run storage --debug=false apply-splitfdstream --socket "$socket_path" "$lowerlayer" |
| 75 | + echo "apply-splitfdstream output: $output" |
| 76 | + [ "$status" -eq 0 ] |
| 77 | + [ "$output" != "" ] |
| 78 | + |
| 79 | + applied_layer="$output" |
| 80 | + |
| 81 | + # Verify the layer was created |
| 82 | + run storage --debug=false layers |
| 83 | + [ "$status" -eq 0 ] |
| 84 | + [[ "$output" =~ "$applied_layer" ]] |
| 85 | + |
| 86 | + # Check that we can mount the applied layer |
| 87 | + run storage --debug=false mount "$applied_layer" |
| 88 | + [ "$status" -eq 0 ] |
| 89 | + [ "$output" != "" ] |
| 90 | + local applied_mount="$output" |
| 91 | + |
| 92 | + # Verify some expected content exists (from populate function) |
| 93 | + [ -f "$applied_mount/layer1file1" ] |
| 94 | + [ -f "$applied_mount/layer1file2" ] |
| 95 | + [ -d "$applied_mount/layerdir1" ] |
| 96 | + |
| 97 | + # Unmount the layer |
| 98 | + run storage unmount "$applied_layer" |
| 99 | + [ "$status" -eq 0 ] |
| 100 | + |
| 101 | + # Kill the server before teardown runs storage wipe (which needs the store lock) |
| 102 | + stop_server |
| 103 | +} |
| 104 | + |
| 105 | +@test "splitfdstream server socket path uses runroot" { |
| 106 | + case "$STORAGE_DRIVER" in |
| 107 | + overlay*) |
| 108 | + ;; |
| 109 | + *) |
| 110 | + skip "driver $STORAGE_DRIVER does not support splitfdstream" |
| 111 | + ;; |
| 112 | + esac |
| 113 | + |
| 114 | + # Get the expected socket path from runroot |
| 115 | + local runroot=`storage status 2>&1 | awk '/^Run Root:/{print $3}'` |
| 116 | + local expected_socket="$runroot/json-rpc.sock" |
| 117 | + |
| 118 | + # Start the JSON-RPC server in the background |
| 119 | + start_server |
| 120 | + |
| 121 | + # Wait for socket to be created (max 10 seconds) |
| 122 | + local count=0 |
| 123 | + while [[ ! -S "$expected_socket" && $count -lt 50 ]]; do |
| 124 | + sleep 0.2 |
| 125 | + count=$((count + 1)) |
| 126 | + done |
| 127 | + |
| 128 | + # Verify the socket is created in the correct location |
| 129 | + [ -S "$expected_socket" ] |
| 130 | + |
| 131 | + # Kill the server before teardown runs storage wipe (which needs the store lock) |
| 132 | + stop_server |
| 133 | +} |
0 commit comments