Add integration tests and fix received message writing to a file in test suit

Add integration tests and fix received message writing to a file in test suit and sending correct number of messages in a multi-threaded environment.