Skip to content

Commit

Permalink
Fixing data object initialization problem
Browse files Browse the repository at this point in the history
Summary: Some of the member variables in data objects were not getting
initialized. That caused resumption test with protocol negotiation to fail.
Fixing that
TODO: ensure that resumption test outputs proper log in case of failure

Reviewed By: @ldemailly, @invalid auth token.

Differential Revision: D2428637
  • Loading branch information
uddipta authored and ldemailly committed Sep 10, 2015
1 parent 89f0ab2 commit eb0ea4b
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 44 deletions.
10 changes: 5 additions & 5 deletions ByteSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ struct SourceMetaData {
* of using full path of the file, we can use this to identify the
* file.
*/
int64_t seqId;
int64_t seqId{0};
/// size of the entire source
int64_t size;
int64_t size{0};
/// file allocation status in the receiver side
FileAllocationStatus allocationStatus;
FileAllocationStatus allocationStatus{NOT_EXISTS};
/// if there is a size mismatch, this is the previous sequence id
int64_t prevSeqId;
int64_t prevSeqId{0};
/// Read the file with these flags
int oFlags;
int oFlags{0};
};

class ByteSource {
Expand Down
3 changes: 2 additions & 1 deletion FileCreator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ int FileCreator::openAndSetSize(BlockDetails const *blockDetails) {
transferLogManager_.addFileCreationEntry(
blockDetails->fileName, blockDetails->seqId, blockDetails->fileSize);
} else {
WDT_CHECK(blockDetails->allocationStatus == EXISTS_TOO_SMALL);
WDT_CHECK(blockDetails->allocationStatus == EXISTS_TOO_SMALL)
<< blockDetails->allocationStatus;
transferLogManager_.addFileResizeEntry(blockDetails->seqId,
blockDetails->fileSize);
}
Expand Down
26 changes: 13 additions & 13 deletions Protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ class FileChunksInfo {

private:
/// seq-id of the file
int64_t seqId_;
int64_t seqId_{0};
/// name of the file
std::string fileName_;
/// size of the file
int64_t fileSize_;
int64_t fileSize_{0};
/// list of chunk info
std::vector<Interval> chunks_;
};
Expand All @@ -163,31 +163,31 @@ struct BlockDetails {
/// name of the file
std::string fileName;
/// sequence-id of the file
int64_t seqId;
int64_t seqId{0};
/// size of the file
int64_t fileSize;
int64_t fileSize{0};
/// offset of the block from the start of the file
int64_t offset;
int64_t offset{0};
/// size of the block
int64_t dataSize;
int64_t dataSize{0};
/// receiver side file allocation status
FileAllocationStatus allocationStatus;
FileAllocationStatus allocationStatus{NOT_EXISTS};
/// seq-id of previous transfer, only valid if there is a size mismatch
int64_t prevSeqId;
int64_t prevSeqId{0};
};

/// structure representing settings cmd
struct Settings {
/// sender side read timeout
int readTimeoutMillis;
int readTimeoutMillis{0};
/// sender side write timeout
int writeTimeoutMillis;
int writeTimeoutMillis{0};
/// transfer-id
std::string transferId;
std::string transferId{0};
/// whether checksum in enabled or not
bool enableChecksum;
bool enableChecksum{0};
/// whether sender wants to read previously transferred chunks or not
bool sendFileChunks;
bool sendFileChunks{0};
};

class Protocol {
Expand Down
18 changes: 16 additions & 2 deletions wdt_download_resumption_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,34 @@

set -o pipefail

restoreIptable() {
if [ -e "$DIR/ip6table" ]; then
# try to restore only if iptable was modified
sudo ip6tables-restore < $DIR/ip6table
fi
}

printServerLog() {
echo "Server log($DIR/server${TEST_COUNT}.log):"
cat $DIR/server${TEST_COUNT}.log
}

checkLastCmdStatus() {
LAST_STATUS=$?
if [ $LAST_STATUS -ne 0 ] ; then
sudo ip6tables-restore < $DIR/ip6table
restoreIptable
echo "exiting abnormally with status $LAST_STATUS - aborting/failing test"
printServerLog
exit $LAST_STATUS
fi
}

checkLastCmdStatusExpectingFailure() {
LAST_STATUS=$?
if [ $LAST_STATUS -eq 0 ] ; then
sudo ip6tables-restore < $DIR/ip6table
restoreIptable
echo "expecting wdt failure, but transfer was successful, failing test"
printServerLog
exit 1
fi
}
Expand Down
15 changes: 14 additions & 1 deletion wdt_network_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,24 @@
# tee. source : http://petereisentraut.blogspot.com/2010/11/pipefail.html
set -o pipefail

restoreIptable() {
if [ -e "$DIR/ip6table" ]; then
# try to restore only if iptable was modified
sudo ip6tables-restore < $DIR/ip6table
fi
}

printServerLog() {
echo "Server log($DIR/server${TEST_COUNT}.log):"
cat $DIR/server${TEST_COUNT}.log
}

checkLastCmdStatus() {
LAST_STATUS=$?
if [ $LAST_STATUS -ne 0 ] ; then
sudo ip6tables-restore < $DIR/ip6table
restoreIptable
echo "exiting abnormally with status $LAST_STATUS - aborting/failing test"
printServerLog
exit $LAST_STATUS
fi
}
Expand Down
38 changes: 16 additions & 22 deletions wdt_port_block_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
from __future__ import print_function
from __future__ import unicode_literals
import os
import re
import subprocess
from time import sleep
from time import time
from urlparse import urlparse
from urlparse import parse_qs
from threading import Thread

receiver_end_time = 0
Expand All @@ -29,35 +28,34 @@ def main():
os.environ[environment_variable_name] == "0"):
print("Test with ipv6 client is disabled in this system")
return
receiver_start_delay = 0.01

receiver_cmd = "_bin/wdt/wdt -start_port 0 -skip_writes -v 1"
print(receiver_cmd)
receiver_start_time = time()
receiver_process = subprocess.Popen(receiver_cmd.split(),
stdout=subprocess.PIPE)

connection_url = receiver_process.stdout.readline().strip()
parse_result = urlparse(connection_url)
query_parse_result = parse_qs(parse_result.query)
port_to_block = query_parse_result['ports'][0].split(',')[0]
url_match = re.search('\?.*ports=([0-9]+).*', connection_url)
rest_of_url = url_match.group(0)
port_to_block = url_match.group(1)

# this sleep is needed to allow receiver to start listening. Otherwise,
# nc will not be able to connect and the port will not be blocked
sleep(receiver_start_delay)
sleep(0.5)

# start a thread to wait for receiver finish
thread = Thread(target=wait_for_receiver_finish,
args=[receiver_process])
thread.start()

sender_cmd = ("(sleep 20 | nc -4 localhost {0}) & "
"(sleep 20 | nc -4 localhost {0}) & "
"_bin/wdt/wdt -directory wdt/ -ipv6 "
"-connection_url \"{1}\"").format(
port_to_block, connection_url)
# we hack the url to be ::1 instead of hostname to increase chances
# it works on machines which do have ipv6 but no dns entry
sender_cmd = ("(sleep 20 | nc -4 localhost {0}) &> /dev/null & "

This comment has been minimized.

Copy link
@ldemailly

ldemailly Sep 12, 2015

Contributor

fixes #70

"(sleep 20 | nc -4 localhost {0}) &> /dev/null & "
"sleep 1; _bin/wdt/wdt -directory wdt/ -ipv6 "
"-connection_url wdt://::1\"{1}\"").format(
port_to_block, rest_of_url)
print(sender_cmd)
sender_start_time = time()
status = os.system(sender_cmd)
sender_end_time = time()

Expand All @@ -68,18 +66,14 @@ def main():
if status != 0:
exit(status)

sender_duration = sender_end_time - sender_start_time
receiver_duration = receiver_end_time - receiver_start_time

receiver_duration -= receiver_start_delay
diff = abs(sender_duration - receiver_duration) * 1000
diff = abs(sender_end_time - receiver_end_time) * 1000
max_allowed_diff = 200
if diff > max_allowed_diff:
print(("Sender and Receiver duration difference {0} is more than "
"allowed duration {1}").format(diff, max_allowed_diff))
print(("Sender and Receiver end time difference {0} is more than "
"allowed diff {1}").format(diff, max_allowed_diff))
exit(1)
print(("Test passed - Sender and Receiver"
" duration diff {0} ms").format(diff))
" end time diff {0} ms").format(diff))

if __name__ == "__main__":
main()

0 comments on commit eb0ea4b

Please sign in to comment.