File: __driver__.lua

package info (click to toggle)
monotone 1.0-6
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 20,708 kB
  • sloc: cpp: 84,765; sh: 6,787; perl: 837; makefile: 833; python: 517; lisp: 379; sql: 118; exp: 88; ansic: 52
file content (148 lines) | stat: -rw-r--r-- 4,631 bytes parent folder | download
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
includecommon("netsync.lua")

mtn_setup()
netsync.setup()


function make_old(ver)
   local exe = "mtn-netsync" .. ver
   if not existsonpath(exe) then
      return nil
   end
   local rcfile
   if get("netsync"..ver..".lua") then
      rcfile = "netsync"..ver..".lua"
   else
      rcfile = "test_hooks.lua"
   end
   local nostd = "--no-standard-rcfiles"
   if ver < 8 then
      nostd = "--nostd"
   end
   local fn = function (...)
                 return {exe, nostd, "--root=.",
                    "--confdir=.",
                    "--rcfile="..rcfile,
                    "--key=tester@test.net",
                    "--db=test"..ver..".mtn",
                    "--keydir=keys",
                    ...}
              end

   check(getstd("test_keys"))
   check(fn("read", "test_keys"), 0, nil, false)
   remove("test_keys")
   return {fn = fn, net_fn = fn,
      reset = function ()
                 check(remove("test"..ver..".mtn"))
                 check(remove("test"..ver..".mtn-journal"))
                 check(fn("db", "init"))
              end
   }
end

current = {fn = mtn, net_fn = mtn,
   reset = function ()
              check(remove("test.db"))
              check(remove("test.db-journal"))
              check(mtn("db", "init"))
           end
}

function make_fake(min_ver, max_ver)
   local fn = function (...)
                 return mtn("--db=test"..max_ver..".mtn", ...)
              end
   local net_fn = function (...)
                     return mtn("--min-netsync-version="..min_ver,
                                "--max-netsync-version="..max_ver,
                                "--db=test"..max_ver..".mtn",
                                ...)
                  end
   return {fn = fn, net_fn = net_fn,
      reset = function ()
                 check(remove("test"..max_ver..".mtn"))
                 check(remove("test"..max_ver..".mtn-journal"))
                 check(fn("db", "init"))
              end
   }
end

function do_commits(my_mtn, dat)
   check(remove("_MTN"))
   check(my_mtn("setup", ".", "--branch=testbranch"))
   check(writefile("base", "base"))
   check(my_mtn("add", "base"), 0, nil, false)
   check(my_mtn("commit", "--message=base commit"), 0, nil, false)

   check(writefile("child", dat))
   check(my_mtn("add", "child"), 0, nil, false)
   check(my_mtn("commit", "--message=child commit"), 0, nil, false)
end

function check_same_revs(cmd1, cmd2)
   check(cmd1, 0, true, false)
   local data1 = {}
   for l in io.lines("stdout") do table.insert(data1, l) end
   check(cmd2, 0, true, false)
   local data2 = {}
   for l in io.lines("stdout") do table.insert(data2, l) end
   L("Command 1 has ", table.getn(data1), " lines.")
   L("Command 2 has ", table.getn(data2), " lines.")
   check(table.getn(data1) == table.getn(data2))
   for i = 1, table.getn(data1) do
      local hash_len = 40
      check(data1[i]:sub(1, hash_len) == data2[i]:sub(1, hash_len))
   end
end

function check_pair(client, server)
   -- setup database contents
   client.reset()
   do_commits(client.fn, "client")
   sleep(2) -- make sure that the date certs are different
   server.reset()
   do_commits(server.fn, "server")

   -- exchange data
   local addr = "localhost:" .. math.random(1024, 65535)
   local srv = bg(server.net_fn("serve", "--rcfile=netsync.lua", "--bind="..addr),
                  false, false, false)
   sleep(1)
   check(client.net_fn("sync", addr, "testbranch"), 0, false, false, false)
   sleep(1)
   srv:finish()

   -- check for correct/matching contents
   check_same_stdout(client.fn("automate", "select", "i:"),
                     server.fn("automate", "select", "i:"))
   check_same_revs(client.fn("heads", "--branch=testbranch"),
		   server.fn("heads", "--branch=testbranch"))
   -- there should be 13 certs - 4 per rev, plus an extra date cert
   -- on the common base revision
   check(client.fn("db", "info"), 0, true)
   check(qgrep("^ *certs .*: *13 *$", "stdout"))
   check(server.fn("db", "info"), 0, true)
   check(qgrep("^ *certs *: *13 *$", "stdout"))
end

function check_against(ver)
   local real_other = make_old(ver)
   if real_other ~= nil then
      check_pair(current, real_other)
      check_pair(real_other, current)
   end
   local fake_other = make_fake(ver, ver)
   check_pair(current, fake_other)
   check_pair(fake_other, current)
end

-- check against compatible versions, both with fake "old" peers,
-- and with real old peers if they're available
check_against(6)
check_against(7)

-- check against a fake far-future version
fake_future = make_fake(1, 250)
check_pair(current, fake_future)
check_pair(fake_future, current)