Skip to content

Commit

Permalink
feat(tests): check MQTT binary file auto-cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dfranusic committed Oct 10, 2023
1 parent e3915a4 commit cc21f2c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
28 changes: 27 additions & 1 deletion test/check_mqtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,26 @@ mqtt_test_04(void **state)
assert_int_equal(r, 0);
assert_non_null(b);
// file uuid returned
if (strlen(b) != 36) {
if (strlen(b) != 73) {
fail();
}

// tokenize
char *valid_uuid = NULL;
char *incomplete_uuid = NULL;
char *token = NULL;
char *saveptr = NULL;

// get valid uuid (all chunks)
token = strtok_r(b, ":", &saveptr);
assert_non_null(token);
valid_uuid = strdup(token);

// get incomplete uuid (only first chunk)
token = strtok_r(NULL, ":", &saveptr);
assert_non_null(token);
incomplete_uuid = strdup(token);

// wait for data
sleep(7);

Expand All @@ -243,8 +260,17 @@ mqtt_test_04(void **state)
}
fclose(f);
assert_int_equal(fsz, 1024);

// incomplete file should have been removed
sleep(5);
strcpy(&fp[strlen(fp) - 36], incomplete_uuid);
FILE *f2 = fopen(fp, "r");
assert_null(f2);

// cleanup
free(b);
free(valid_uuid);
free(incomplete_uuid);
}

int
Expand Down
13 changes: 11 additions & 2 deletions test/mqtt_test_04.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
cmd = {
local cmd = {
"CMD_MQTT_BINARY_UPLOAD",
"mqtt_local",
1024
}

local cmd2 = {
"CMD_MQTT_BINARY_UPLOAD",
"mqtt_local",
1024
}

-- run
local d = M.cmd_call(cmd)
local d2 = M.cmd_call(cmd)
-- notify upload script to start
-- sending 256 byte chunks
os.execute("echo \"" .. d[3].file_uuid .. "\" > /tmp/tmp_file_uuid")
return d[3].file_uuid
os.execute("echo \"" .. d2[3].file_uuid .. "\" > /tmp/tmp_file_uuid_timeout")
return d[3].file_uuid .. ":" .. d2[3].file_uuid
3 changes: 3 additions & 0 deletions test/test_bin_upload.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ do
# chunk 03
echo "Uploading chunk 03"
mosquitto_pub -h 127.0.0.1 -t "mink.bin/DEBUG_UUID/$UUID/upload" -f /tmp/xad -u user -P password
# one chunk for the file upload which is supposed to timeout
UUID2=$(cat /tmp/tmp_file_uuid_timeout)
mosquitto_pub -h 127.0.0.1 -t "mink.bin/DEBUG_UUID/$UUID2/upload" -f /tmp/xad -u user -P password
sleep 2
CSUM2=$(sha256sum -z /tmp/mink.bin/$UUID|cut -d' ' -f1)
if [ $CSUM1 != $CSUM2 ]; then
Expand Down

0 comments on commit cc21f2c

Please sign in to comment.