mirror of
https://github.com/s3fs-fuse/s3fs-fuse.git
synced 2024-12-23 01:08:54 +00:00
Merge pull request #146 from kahing/exit_handler_for_test
add exit handler to cleanup on failures
This commit is contained in:
commit
37f9bbd231
@ -1,4 +1,8 @@
|
||||
#!/bin/bash -e
|
||||
#!/bin/bash
|
||||
|
||||
set -o xtrace
|
||||
set -o errexit
|
||||
|
||||
COMMON=integration-test-common.sh
|
||||
source $COMMON
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
static const char FILE_CONTENT[] = "XXXX";
|
||||
#define PROG "rename_before_close"
|
||||
|
||||
static char *
|
||||
filename_to_mkstemp_template(const char *file)
|
||||
@ -25,6 +26,7 @@ static off_t
|
||||
get_file_size(const char *file)
|
||||
{
|
||||
struct stat ss;
|
||||
printf(PROG ": stat(%s)\n", file);
|
||||
int ret = lstat(file, &ss);
|
||||
assert(ret == 0);
|
||||
return ss.st_size;
|
||||
@ -34,29 +36,48 @@ static void
|
||||
test_rename_before_close(const char *file)
|
||||
{
|
||||
char *template = filename_to_mkstemp_template(file);
|
||||
printf(PROG ": mkstemp(%s)\n", template);
|
||||
int fd = mkstemp(template);
|
||||
assert(fd >= 0);
|
||||
|
||||
sleep(1);
|
||||
|
||||
printf(PROG ": write(%s)\n", template);
|
||||
int ret = write(fd, FILE_CONTENT, sizeof(FILE_CONTENT));
|
||||
assert(ret == sizeof(FILE_CONTENT));
|
||||
|
||||
sleep(1);
|
||||
|
||||
printf(PROG ": fsync(%s)\n", template);
|
||||
ret = fsync(fd);
|
||||
assert(ret == 0);
|
||||
|
||||
sleep(1);
|
||||
|
||||
assert(get_file_size(template) == sizeof(FILE_CONTENT));
|
||||
|
||||
sleep(1);
|
||||
|
||||
printf(PROG ": rename(%s, %s)\n", template, file);
|
||||
ret = rename(template, file);
|
||||
assert(ret == 0);
|
||||
|
||||
sleep(1);
|
||||
|
||||
printf(PROG ": close(%s)\n", file);
|
||||
ret = close(fd);
|
||||
assert(ret == 0);
|
||||
|
||||
sleep(1);
|
||||
|
||||
assert(get_file_size(file) == sizeof(FILE_CONTENT));
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
setvbuf(stdout, NULL, _IONBF, 0);
|
||||
|
||||
if (argc < 2) {
|
||||
printf("Usage: %s <file>", argv[0]);
|
||||
return 1;
|
||||
|
@ -1,12 +1,40 @@
|
||||
#!/bin/bash -e
|
||||
#!/bin/bash
|
||||
|
||||
set -o xtrace
|
||||
set -o errexit
|
||||
|
||||
# Require root
|
||||
REQUIRE_ROOT=require-root.sh
|
||||
#source $REQUIRE_ROOT
|
||||
source integration-test-common.sh
|
||||
|
||||
java -jar "$S3PROXY_BINARY" --properties s3proxy.conf &
|
||||
S3PROXY_PID="$!"
|
||||
function retry {
|
||||
set +o errexit
|
||||
N=$1; shift;
|
||||
status=0
|
||||
for i in $(seq $N); do
|
||||
$@
|
||||
status=$?
|
||||
if [ $status == 0 ]; then
|
||||
break
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
|
||||
if [ $status != 0 ]; then
|
||||
echo "timeout waiting for $@"
|
||||
fi
|
||||
set -o errexit
|
||||
return $status
|
||||
}
|
||||
|
||||
function exit_handler {
|
||||
kill $S3PROXY_PID
|
||||
retry 30 fusermount -u $TEST_BUCKET_MOUNT_POINT_1
|
||||
}
|
||||
trap exit_handler EXIT
|
||||
|
||||
stdbuf -oL -eL java -jar "$S3PROXY_BINARY" --properties s3proxy.conf | stdbuf -oL -eL sed -u "s/^/s3proxy: /" &
|
||||
|
||||
# wait for S3Proxy to start
|
||||
for i in $(seq 30);
|
||||
@ -20,22 +48,22 @@ do
|
||||
sleep 1
|
||||
done
|
||||
|
||||
S3PROXY_PID=$(netstat -lpnt | grep :8080 | awk '{ print $7 }' | sed -u 's|/java||')
|
||||
|
||||
# Mount the bucket
|
||||
if [ ! -d $TEST_BUCKET_MOUNT_POINT_1 ]
|
||||
then
|
||||
mkdir -p $TEST_BUCKET_MOUNT_POINT_1
|
||||
fi
|
||||
$S3FS $TEST_BUCKET_1 $TEST_BUCKET_MOUNT_POINT_1 \
|
||||
stdbuf -oL -eL $S3FS $TEST_BUCKET_1 $TEST_BUCKET_MOUNT_POINT_1 \
|
||||
-o createbucket \
|
||||
-o passwd_file=$S3FS_CREDENTIALS_FILE \
|
||||
-o sigv2 \
|
||||
-o url=http://127.0.0.1:8080 \
|
||||
-o use_path_request_style
|
||||
-o use_path_request_style -f -o f2 -d -d |& stdbuf -oL -eL sed -u "s/^/s3fs: /" &
|
||||
|
||||
retry 30 grep $TEST_BUCKET_MOUNT_POINT_1 /proc/mounts || exit 1
|
||||
|
||||
./integration-test-main.sh $TEST_BUCKET_MOUNT_POINT_1
|
||||
|
||||
fusermount -u $TEST_BUCKET_MOUNT_POINT_1
|
||||
|
||||
kill $S3PROXY_PID
|
||||
|
||||
echo "All tests complete."
|
||||
|
Loading…
Reference in New Issue
Block a user