1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
includecommon("netsync.lua")
mtn_setup()
netsync.setup_with_notes()
-- This tests *some* of the netsync error code handling. It can't test
-- reporting of interrupted connections (21x) because we don't have a
-- reliable way to kill one side halfway through the connection,
-- and can't test 5xx errors because those require that one side isn't
-- speaking the protocol correctly.
function get_errcode(who)
canonicalize("testnotes-" .. who .. ".log")
local dat = readfile("testnotes-" .. who .. ".log")
local _, _, errcode = string.find(dat, "\n%d+ end: status = (%d+)\n")
if errcode == nil then errcode = "<missing>" end
L("Error code for ", who, " is ", errcode)
return errcode
end
function chk_errcode_is(errcode, which)
L("Want error code ", errcode)
errcode = string.gsub(errcode, "x", ".")
if which == nil then
local srvcode = get_errcode("server")
local clicode = get_errcode("client")
check(string.find(srvcode, errcode) ~= nil)
check(string.find(clicode, errcode) ~= nil)
else
local code = get_errcode(which)
check(string.find(code, errcode) ~= nil)
end
end
function clearnotes()
check(remove("testnotes-client.log"))
check(remove("testnotes-server.log"))
end
addfile("testfile", "file contents")
commit()
addfile("otherfile", "other contents")
commit("otherbranch")
netsync.sync("testbranch")
chk_errcode_is(200)
clearnotes()
writefile("denyread", "function get_netsync_read_permitted() return false end")
srv = netsync.start({"--rcfile=denyread"})
srv:sync({"otherbranch"}, 2, 1)
srv:stop()
chk_errcode_is(412)
clearnotes()
check(mtn2("genkey", "unknown@tester.net"), 0, false, false, string.rep("unknown@tester.net\n", 2))
srv = netsync.start()
srv:sync({"testbranch", "--key=unknown@tester.net"}, 2, 1)
srv:stop()
chk_errcode_is(412) -- anonymous write (was 422 unknown key)
clearnotes()
check(mtn("db", "set_epoch", "testbranch", string.rep("0", 40)))
check(mtn2("db", "set_epoch", "testbranch", string.rep("1", 40)))
srv = netsync.start()
srv:push({"testbranch"}, 2, 1)
srv:stop()
chk_errcode_is(432)
clearnotes()
|