diff --git a/.github/workflows/nbnet.yml b/.github/workflows/nbnet.yml index 2855259..5fed6eb 100644 --- a/.github/workflows/nbnet.yml +++ b/.github/workflows/nbnet.yml @@ -215,8 +215,6 @@ jobs: cd build cmake -DLIBDATACHANNEL_LIBRARY_PATH=${{ github.workspace }}/libdatachannel/build/libdatachannel.so -DLIBDATACHANNEL_INCLUDE_PATH=${{ github.workspace }}/libdatachannel/include -DWEBRTC_C_DRIVER=ON .. make - cd .. - npm install - name: Compile soak test (web) run: | cd emsdk @@ -226,6 +224,8 @@ jobs: cd build_web emcmake cmake .. make + cd .. + npm install - name: Run soak test run: WEBRTC_NATIVE=1 timeout 240 ./bin/github-actions/run_soak.sh diff --git a/bin/github-actions/run_soak.sh b/bin/github-actions/run_soak.sh index 9149b75..7d10938 100755 --- a/bin/github-actions/run_soak.sh +++ b/bin/github-actions/run_soak.sh @@ -8,6 +8,49 @@ CHANNEL_COUNT=3 MESSAGE_COUNT=500 NODE_CMD="$EMSDK_NODE --experimental-wasm-threads" +run_client () { + node_client=$1 + echo "Running soak client (run in node: $node_client)..." + + if [ $node_client -eq 1 ] + then + $NODE_CMD build_web/client.js --message_count=$MESSAGE_COUNT --channel_count=$CHANNEL_COUNT --packet_loss=$PACKET_LOSS --packet_duplication=$PACKET_DUPLICATION --ping=$PING --jitter=$JITTER &> soak_cli_out + else + ./build/client --message_count=$MESSAGE_COUNT --channel_count=$CHANNEL_COUNT --packet_loss=$PACKET_LOSS --packet_duplication=$PACKET_DUPLICATION --ping=$PING --jitter=$JITTER &> soak_cli_out + fi + + RESULT=$? + + # when running the soak test in the latest version of emscripten with node 16 + # the client aborts at the end when calling emscripten_force_exit + # I could not figure out why, hence the condition + [[ $node_client -eq 1 ]] && EXPECTED_RESULT=7 || EXPECTED_RESULT=0 + + if [ $RESULT -eq $EXPECTED_RESULT ] + then + echo "Soak test completed with success!" + echo "Printing the end of client logs..." + + tail -n 150 soak_cli_out + + return 0 + else + echo "Soak test failed! (code: $RESULT)" + echo "Printing the end of client logs..." + tail -n 150 soak_cli_out + echo "Printing the end of server logs..." + tail -n 150 soak_serv_out + + return 1 + fi +} + +exit_soak () { + kill -SIGINT $SERV_PID 2> /dev/null + + exit $1 +} + cd soak echo "Starting soak server..." @@ -33,36 +76,18 @@ sleep 3 if [ -n "$WEBRTC" ] then - $NODE_CMD build/client.js --message_count=$MESSAGE_COUNT --channel_count=$CHANNEL_COUNT --packet_loss=$PACKET_LOSS --packet_duplication=$PACKET_DUPLICATION --ping=$PING --jitter=$JITTER &> soak_cli_out -else - ./build/client --message_count=$MESSAGE_COUNT --channel_count=$CHANNEL_COUNT --packet_loss=$PACKET_LOSS --packet_duplication=$PACKET_DUPLICATION --ping=$PING --jitter=$JITTER &> soak_cli_out -fi - -RESULT=$? - -# when running the soak test in the latest version of emscripten with node 16 -# the client aborts at the end when calling emscripten_force_exit -# I could not figure out why, hence the condition -[[ -n "$WEBRTC" ]] && EXPECTED_RESULT=7 || EXPECTED_RESULT=0 - -if [ $RESULT -eq $EXPECTED_RESULT ] -then - echo "Soak test completed with success!" - echo "Printing the end of client logs..." - - tail -n 150 soak_cli_out + run_client 1 - EXIT_CODE=0 + exit_soak $? else - echo "Soak test failed! (code: $RESULT)" - echo "Printing the end of client logs..." - tail -n 150 soak_cli_out - echo "Printing the end of server logs..." - tail -n 150 soak_serv_out + if [ -n "$WEBRTC_NATIVE" ] + then + # run both UDP and webrtc clients on the same server - EXIT_CODE=1 + if run_client 0 && run_client 1; then + exit_soak 0 + else + exit_soak 1 + fi + fi fi - -kill -SIGINT $SERV_PID 2> /dev/null - -exit $EXIT_CODE diff --git a/net_drivers/webrtc_c.h b/net_drivers/webrtc_c.h index 19ffb5d..76e7aad 100644 --- a/net_drivers/webrtc_c.h +++ b/net_drivers/webrtc_c.h @@ -610,7 +610,8 @@ static void NBN_WebRTC_C_ServStop(void) static int NBN_WebRTC_C_ServRecvPackets(void) { - int size; + const int buffer_size = sizeof(nbn_wrtc_c_serv.packet_buffer); + int size = buffer_size; for (unsigned int i = 0; i < nbn_wrtc_c_serv.peers->capacity; i++) { @@ -618,9 +619,7 @@ static int NBN_WebRTC_C_ServRecvPackets(void) if (entry) { - size = NBN_PACKET_MAX_SIZE; - - while (rtcReceiveMessage(entry->peer->channel_id, nbn_wrtc_c_serv.packet_buffer, &size) != RTC_ERR_NOT_AVAIL) + while (rtcReceiveMessage(entry->peer->channel_id, nbn_wrtc_c_serv.packet_buffer, &size) == RTC_ERR_SUCCESS) { NBN_Packet packet; @@ -629,6 +628,7 @@ static int NBN_WebRTC_C_ServRecvPackets(void) packet.sender = entry->peer->conn; NBN_Driver_RaiseEvent(NBN_DRIVER_SERV_CLIENT_PACKET_RECEIVED, &packet); + size = buffer_size; } } } diff --git a/soak/soak_cli_out b/soak/soak_cli_out deleted file mode 100644 index 2e2fc8d..0000000 --- a/soak/soak_cli_out +++ /dev/null @@ -1 +0,0 @@ -./bin/github-actions/run_soak.sh: line 38: ./client: No such file or directory diff --git a/soak/soak_serv_out b/soak/soak_serv_out deleted file mode 100644 index 64a43ed..0000000 --- a/soak/soak_serv_out +++ /dev/null @@ -1 +0,0 @@ -./bin/github-actions/run_soak.sh: line 18: ./server: No such file or directory