# # # patch "tests/(normal)_netsync_on_partially_unrelated_revisions/__driver__.lua" # from [1581e71b144754fbec637bcd212c8c424dcfa1b7] # to [ba7f6002567f543835f899351d0b9ccc657302f8] # # patch "tests/exchanging_work_via_netsync/__driver__.lua" # from [f6c1718742a80d452437f19101dcc41ba9574479] # to [fa77d92622ec4fffa856326dcc98a1e90988ac76] # # patch "tests/netsync_transfers_public_keys/__driver__.lua" # from [c722036c34b5f223c1ab9ce1972067f15b848930] # to [be1446c019833ef0be51f560d39767aee6ded881] # # patch "tests/persistent_netsync_server_-_keys/__driver__.lua" # from [eae1ebfb480390a12c894c2fad7425a85ccaa3df] # to [23f5e46ab0916fa3be47fad94e77d9a9fce06e7f] # # patch "tests/persistent_netsync_server_-_revs_&_certs/__driver__.lua" # from [a77842fd1bbe971e12a5eb922d12b188530b26cd] # to [138dd2eebf0cde0914a678facee439f8186914a7] # # patch "tests/repeatedly_exchanging_work_via_netsync/__driver__.lua" # from [22d7b50f5a96ed4c3813f26293821d2a9feb3aad] # to [3e6428db18e19dc383f3fe3cef9b4f2b28b6fc84] # # patch "tests/single_manifest_netsync/__driver__.lua" # from [1a5b0b9698c3b6b2a1f40405475ce06e307a7a8e] # to [830f2ffecf6cb342af16a385146a750fede897de] # # patch "testsuite.lua" # from [2f1522737ecaeb9d3308e3ca2a734b8d84be7de4] # to [03425ee5785ef783a5f6b86bdac9e82e2553432e] # ============================================================ --- tests/(normal)_netsync_on_partially_unrelated_revisions/__driver__.lua 1581e71b144754fbec637bcd212c8c424dcfa1b7 +++ tests/(normal)_netsync_on_partially_unrelated_revisions/__driver__.lua ba7f6002567f543835f899351d0b9ccc657302f8 @@ -17,13 +17,13 @@ -- mentioned there; doing sideways deltas between heads, all sorts of -- possibilities for maybe-efficient algorithms. -netsync_setup() +netsync.setup() addfile("testfile1", "This is test file 1") commit("testbranch") base = base_revision() -run_netsync("pull", "testbranch") +netsync.pull("testbranch") for _,i in pairs{{"automate", "graph"}, {"ls", "certs", base}} do check_same_stdout(cmd(mtn(unpack(i))), cmd(mtn2(unpack(i)))) @@ -40,7 +40,7 @@ check(cmd(mtn("update")), 0, false, false) merge = base_revision() -run_netsync("pull", "testbranch") +netsync.pull("testbranch") check_same_stdout(cmd(mtn("automate", "graph")), cmd(mtn2("automate", "graph"))) for _,i in pairs{base, unrelated, merge} do ============================================================ --- tests/exchanging_work_via_netsync/__driver__.lua f6c1718742a80d452437f19101dcc41ba9574479 +++ tests/exchanging_work_via_netsync/__driver__.lua fa77d92622ec4fffa856326dcc98a1e90988ac76 @@ -1,6 +1,6 @@ mtn_setup() -netsync_setup() +netsync.setup() writefile("testfile", "version 0 of test file") check(cmd(mtn("add", "testfile")), 0, false, false) @@ -15,7 +15,7 @@ f_ver[1] = sha1("testfile") ver[1] = base_revision() -run_netsync("pull", "testbranch") +netsync.pull("testbranch") check(cmd(mtn2("ls", "certs", ver[0])), 0, true) rename("stdout", "certs") ============================================================ --- tests/netsync_transfers_public_keys/__driver__.lua c722036c34b5f223c1ab9ce1972067f15b848930 +++ tests/netsync_transfers_public_keys/__driver__.lua be1446c019833ef0be51f560d39767aee6ded881 @@ -1,6 +1,6 @@ mtn_setup() -netsync_setup() +netsync.setup() pubkey = "52f32ec62128ea3541ebdd9d17400e268cfcd3fe" privkey = "06b040c37796863b53f10dc23fcccf379cc2e259" @@ -13,15 +13,15 @@ addfile("testfile", "version 0 of test file") commit("testbranch") -run_netsync("pull", "testbranch") +netsync.pull("testbranch") check(cmd(mtn2("ls", "keys")), 0, true, false) check(not qgrep(pubkey, "stdout")) check(not qgrep(privkey, "stdout")) -- Now check that --key-to-push works. -srv = netsync_serve_start("testbranch", 2) -check(cmd(mtn("--rcfile=netsync.lua", "push", netsync_address, +srv = netsync.start("testbranch", 2) +check(cmd(mtn("--rcfile=netsync.lua", "push", srv.address, "testbranch", "address@hidden")), 0, false, false) srv:finish() @@ -33,7 +33,7 @@ check(cmd(mtn("--branch=testbranch", "--message=blah-blah", "address@hidden", "commit")), 0, false, false) -run_netsync("pull", "testbranch") +netsync.pull("testbranch") check(cmd(mtn2("ls", "keys")), 0, true, false) check(qgrep(pubkey, "stdout")) ============================================================ --- tests/persistent_netsync_server_-_keys/__driver__.lua eae1ebfb480390a12c894c2fad7425a85ccaa3df +++ tests/persistent_netsync_server_-_keys/__driver__.lua 23f5e46ab0916fa3be47fad94e77d9a9fce06e7f @@ -1,6 +1,6 @@ mtn_setup() -netsync_setup() +netsync.setup() writefile("testfile", "I am you and you are me and we are all together.") check(cmd(mtn2("add", "testfile")), 0, false, false) @@ -8,10 +8,10 @@ check(cmd(mtn2("genkey", "address@hidden")), 0, false, false, string.rep("address@hidden",2)) -srv = netsync_serve_start("testbranch") +srv = netsync.start("testbranch") -netsync_client_run("push", "testbranch", 2) -netsync_client_run("pull", "testbranch", 3) +srv:push("testbranch", 2) +srv:pull("testbranch", 3) check(cmd(mtn3("ls", "keys")), 0, true, false) check(not qgrep("address@hidden", "stdout")) @@ -19,8 +19,8 @@ writefile("testfile", "stuffty stuffty") check(cmd(mtn2("commit", "--branch=testbranch", "--message=foo", "address@hidden")), 0, false, false) -netsync_client_run("push", "testbranch", 2) -netsync_client_run("pull", "testbranch", 3) +srv:push("testbranch", 2) +srv:pull("testbranch", 3) srv:finish() ============================================================ --- tests/persistent_netsync_server_-_revs_&_certs/__driver__.lua a77842fd1bbe971e12a5eb922d12b188530b26cd +++ tests/persistent_netsync_server_-_revs_&_certs/__driver__.lua 138dd2eebf0cde0914a678facee439f8186914a7 @@ -1,6 +1,6 @@ mtn_setup() -netsync_setup() +netsync.setup() revs = {} @@ -16,10 +16,10 @@ check(cmd(mtn3("commit", "--branch=testbranch", "--message=foo")), 0, false, false) revs[2] = base_revision() -srv = netsync_serve_start("testbranch") +srv = netsync.start("testbranch") -netsync_client_run("sync", "testbranch", 2) -netsync_client_run("sync", "testbranch", 3) +srv:sync("testbranch", 2) +srv:sync("testbranch", 3) function chksy(n, co_mtn) check_same_stdout(cmd(mtn2("automate", "get_revision", revs[n])), @@ -32,7 +32,7 @@ chksy(1, mtn3) -netsync_client_run("sync", "testbranch", 2) +srv:sync("testbranch", 2) chksy(2, mtn2) -- And now make sure it works for children, where there are diffs and all @@ -50,8 +50,8 @@ -- And add a cert on an old revision check(cmd(mtn3("comment", revs[1], 'sorry dave')), 0, false, false) -netsync_client_run("sync", "testbranch", 3) -netsync_client_run("sync", "testbranch", 2) +srv:sync("testbranch", 3) +srv:sync("testbranch", 2) chksy(3, mtn2) @@ -59,7 +59,7 @@ check_same_stdout(cmd(mtn2("ls", "certs", revs[1])), cmd(mtn3("ls", "certs", revs[1]))) -netsync_client_run("sync", "testbranch", 3) +srv:sync("testbranch", 3) chksy(4, mtn3) ============================================================ --- tests/repeatedly_exchanging_work_via_netsync/__driver__.lua 22d7b50f5a96ed4c3813f26293821d2a9feb3aad +++ tests/repeatedly_exchanging_work_via_netsync/__driver__.lua 3e6428db18e19dc383f3fe3cef9b4f2b28b6fc84 @@ -1,13 +1,13 @@ mtn_setup() -netsync_setup() +netsync.setup() addfile("testfile", "version 0 data") commit("testbranch") ver = {} ver[0] = base_revision() -run_netsync("pull", "testbranch") +netsync.pull("testbranch") addfile("testfile2", "some data") commit("testbranch") @@ -23,7 +23,7 @@ check(cmd(mtn("update")), 0, false, false) ver[3] = base_revision() -run_netsync("pull", "testbranch") +netsync.pull("testbranch") check_same_stdout(cmd(mtn("automate", "graph")), cmd(mtn2("automate", "graph"))) ============================================================ --- tests/single_manifest_netsync/__driver__.lua 1a5b0b9698c3b6b2a1f40405475ce06e307a7a8e +++ tests/single_manifest_netsync/__driver__.lua 830f2ffecf6cb342af16a385146a750fede897de @@ -1,6 +1,6 @@ mtn_setup() -netsync_setup() +netsync.setup() writefile("testfile", "version 0 of test file") check(cmd(mtn("add", "testfile")), 0, false, false) @@ -8,7 +8,7 @@ f_ver = sha1("testfile") ver = base_revision() -run_netsync("pull", "testbranch") +netsync.pull("testbranch") check(cmd(mtn2("ls", "certs", ver)), 0, true) rename("stdout", "certs") ============================================================ --- testsuite.lua 2f1522737ecaeb9d3308e3ca2a734b8d84be7de4 +++ testsuite.lua 03425ee5785ef783a5f6b86bdac9e82e2553432e @@ -64,36 +64,48 @@ -- netsync -netsync_address = nil +function mtn2(...) + return mtn("--db=test2.db", "--keydir=keys2", unpack(arg)) +end -function netsync_setup() +function mtn3(...) + return mtn("--db=test3.db", "--keydir=keys3", unpack(arg)) +end + +netsync = {} +netsync.internal = {} + +function netsync.setup() copyfile("test.db", "test2.db") copy_recursive("keys", "keys2") copyfile("test.db", "test3.db") copy_recursive("keys", "keys3") getstdfile("tests/netsync.lua", "netsync.lua") - netsync_address = "localhost:" .. math.random(20000, 50000) end -function netsync_setup_with_notes() - netsync_setup() +function netsync.setup_with_notes() + netsync.setup() getstdfile("tests/netsync_with_notes.lua", "netsync.lua") end -function mtn2(...) - return mtn("--db=test2.db", "--keydir=keys2", unpack(arg)) +function netsync.internal.client(srv, oper, pat, n, res) + if pat == "" or pat == nil then pat = "*" end + if n == nil then n = 2 end + check(cmd(mtn("--rcfile=netsync.lua", "--keydir=keys"..n, + "--db=test"..n..".db", oper, srv.address, pat)), + res, false, false) end +function netsync.internal.pull(srv, pat, n, res) srv:client("pull", pat, n, res) end +function netsync.internal.push(srv, pat, n, res) srv:client("push", pat, n, res) end +function netsync.internal.sync(srv, pat, n, res) srv:client("sync", pat, n, res) end -function mtn3(...) - return mtn("--db=test3.db", "--keydir=keys3", unpack(arg)) -end - -function netsync_serve_start(pat, n, min) +function netsync.start(pat, n, min) if pat == "" or pat == nil then pat = "*" end local args = {} local fn = mtn + local addr = "localhost:" .. math.random(20000, 50000) table.insert(args, "--dump=_MTN/server_dump") - table.insert(args, "--bind="..netsync_address) + table.insert(args, "--bind="..addr) if min then fn = minhooks_mtn else @@ -110,22 +122,23 @@ while fsize(out.prefix .. "stderr") == 0 do sleep(1) end + out.address = addr + local mt = getmetatable(out) + mt.client = netsync.internal.client + mt.pull = netsync.internal.pull + mt.push = netsync.internal.push + mt.sync = netsync.internal.sync return out end -function netsync_client_run(oper, pat, n, res) - if pat == "" or pat == nil then pat = "*" end - if n == nil then n = 2 end - check(cmd(mtn("--rcfile=netsync.lua", "--keydir=keys"..n, - "--db=test"..n..".db", oper, netsync_address, pat)), - res, false, false) -end - -function run_netsync(oper, pat) - local srv = netsync_serve_start(pat) - netsync_client_run(oper, pat, 0) +function netsync.internal.run(oper, pat) + local srv = netsync.start(pat) + srv:client(oper, pat) srv:finish() end +function netsync.pull(pat) netsync.internal.run("pull", pat) end +function netsync.push(pat) netsync.internal.run("push", pat) end +function netsync.sync(pat) netsync.internal.run("sync", pat) end