2 #include "uniconfroot.h"
3 #include "unitempgen.h"
4 #include "uniretrygen.h"
5 #include "uniclientgen.h"
6 #include "uniconfgen-sanitytest.h"
7 #include "wvfileutils.h"
14 struct UniRetryGenTester
20 socket("/tmp/uniretrygen-uniconfd-%s", getpid()),
21 ini("/tmp/uniretrygen-uniconfd.ini-%s", getpid()),
27 void wait_for_daemon(UniRetryGenTester t
)
29 UniConfRoot
another_cfg(WvString("retry:unix:%s", t
.socket
));
33 another_cfg
.xset("wait", "pong");
34 if (another_cfg
.xget("wait") == "pong") break;
35 fprintf(stderr
, "still waiting for connection.\n");
39 fprintf(stderr
, "managed to connect\n");
43 WVTEST_MAIN("UniRetryGen Sanity Test")
45 UniRetryGen
*gen
= new UniRetryGen("temp:");
46 UniConfGenSanityTester::sanity_test(gen
, "retry:temp:");
50 WVTEST_MAIN("UniRetryGen: uniconfd")
52 signal(SIGPIPE
, SIG_IGN
);
58 UniConfRoot
cfg(WvString("retry:unix:%s 100", t
.socket
));
59 cfg
["/key"].setme("value");
60 WVPASS(!cfg
["/key"].exists());
63 UniConfTestDaemon
daemon(t
.socket
, WvString("ini:%s", t
.ini
));
66 wvdelay(100); // guarantee that the retry interval has expired
67 cfg
["/key"].setme("value");
68 WVPASSEQ(cfg
["/key"].getme(), "value");
73 // no delay necessary: we disconnect right away
74 WVPASS(!cfg
["/key"].exists());
77 UniConfTestDaemon
daemon(t
.socket
, WvString("ini:%s", t
.ini
));
80 wvdelay(100); // guarantee that the retry interval has expired
81 WVPASSEQ(cfg
["/key"].getme(), "value");
86 WVPASS(!cfg
["/key"].exists());
89 bool reconnected
= false;
90 void reconnect_cb(UniRetryGen
&uni
)
91 { reconnected
= true; }
93 WVTEST_MAIN("UniRetryGen: reconnect callback")
95 signal(SIGPIPE
, SIG_IGN
);
101 cfg
.mountgen(new UniRetryGen(WvString("unix:%s", t
.socket
),
102 UniRetryGen::ReconnectCallback(reconnect_cb
), 100));
106 UniConfTestDaemon
daemon(t
.socket
, WvString("ini:%s", t
.ini
));
109 wvdelay(100); // guarantee that the retry interval has expired
110 cfg
.getme(); // Do something to reconnect
114 WVTEST_MAIN("UniRetryGen: immediate reconnect")
116 signal(SIGPIPE
, SIG_IGN
);
122 // Need to set the reconnect delay to 0 to read immediately
123 UniConfRoot
cfg(WvString("retry:unix:%s 0", t
.socket
));
126 UniConfTestDaemon
daemon(t
.socket
, WvString("ini:%s", t
.ini
));
129 cfg
["/key"].setme("value");
130 WVPASSEQ(cfg
["/key"].getme(), "value");
135 // don't check anything before restarting so cfg doesn't know that
136 // uniconfd has disconnected.
138 UniConfTestDaemon
daemon(t
.socket
, WvString("ini:%s", t
.ini
));
141 cfg
.getme(); // Do something to reconnect
142 WVPASSEQ(cfg
["/key"].getme(), "value");
145 WVPASS(!cfg
["/key"].exists());
149 WVTEST_MAIN("UniRetryGen: mount point exists")
152 UniConfRoot
uniconf("temp:");
154 WVPASS(uniconf
["foo"].mount("retry:unix:/tmp/foobar"));
156 WVPASS(uniconf
["foo"].exists());
157 WVPASSEQ(uniconf
["foo"].xget("", WvString::null
), "");
159 WVFAIL(uniconf
["foo/bar"].exists());
160 WVPASSEQ(uniconf
["foo"].xget(""), WvString::null
);