Skip to content

Commit

Permalink
test: add tests for watch_transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardacoppo committed Dec 5, 2024
1 parent ff58314 commit a23c520
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions test/cli/test_log_runtime_archive_main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require "syskit/test/self"
require "syskit/cli/log_runtime_archive_main"
require "syskit/roby_app/tmp_root_ca"

module Syskit
module CLI
Expand Down Expand Up @@ -128,6 +129,50 @@ def call_archive(root_path, archive_path, low_limit, freed_limit)
end
end

describe "#watch_transfer" do
before do
@src_dir = make_tmppath
@tgt_dir = make_tmppath
@archive_dir = make_tmppath
host = "127.0.0.1"
ca = RobyApp::TmpRootCA.new(host)
user = "nilvo"
password = "nilvo123"

server = spawn_server(@tgt_dir, user, password, ca)
port = server.port

@server_params = {
host: host, port: port, certificate: "",
user: user, password: password
}

end

it "calls transfer with the specified period" do
quit = Class.new(RuntimeError)
called = 0
flexmock(LogRuntimeArchive)
.new_instances
.should_receive(:process_transfer)
.pass_thru do
called += 1
raise quit if called == 3
end

tic = Time.now
assert_raises(quit) do
LogRuntimeArchiveMain.start(
["watch_transfer",
@src_dir, @tgt_dir, @server_params, "--period", 0.5]
)
end

assert called == 3
assert_operator(Time.now - tic, :>, 0.9)
end
end

# Mock files sizes in bytes
# @param [Array] size of files in MB
def mock_files_size(sizes)
Expand All @@ -149,6 +194,13 @@ def mock_available_space(total_available_disk_space)
end
end

def spawn_server(tgt_dir, user, password, ca)
LogRuntimeArchiveMain.start(
["transfer_server",
tgt_dir, user, password, ca.private_certificate_path]
)
end

def assert_deleted_files(deleted_files)
if deleted_files.empty?
files = @archive_dir.each_child.select(&:file?)
Expand Down

0 comments on commit a23c520

Please sign in to comment.