Skip to content

Commit ea202a4

Browse files
author
wulei
committed
eunit test
1 parent d8c6ee6 commit ea202a4

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

c_src/elmdb_nif.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,12 @@ static ERL_NIF_TERM elmdb_init(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv
123123
CHECK(mdb_env_set_maxdbs(ctx, 256), err2);
124124
CHECK(mdb_env_set_mapsize(ctx, 10485760), err2);
125125

126-
unsigned int envFlags = 0;
126+
unsigned int envFlags = 0 | MDB_NOTLS;
127127
CHECK(mdb_env_open(ctx, dirname, envFlags, 0664), err2);
128128

129129
// Each transaction belongs to one thread.
130130
// The MDB_NOTLS flag changes this for read-only transactions
131-
// CHECK(mdb_env_set_flags(handle->env, MDB_NOTLS, 1), err2);
131+
// CHECK(mdb_env_set_flags(ctx, MDB_NOTLS, 1), err2);
132132

133133
MDB_txn *txn = NULL;
134134
CHECK(mdb_txn_begin(ctx, NULL, MDB_RDONLY, &txn), err2);

test/elmdb_test.erl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
-module(elmdb_test).
2+
3+
-include_lib("eunit/include/eunit.hrl").
4+
5+
startup() ->
6+
Dir = "./mytestdb1/",
7+
filelib:ensure_dir(Dir),
8+
D = elmdb:init(Dir),
9+
D.
10+
11+
teardown(_) ->
12+
Dir = "./mytestdb1/",
13+
[file:delete(F) || F <- filelib:wildcard(Dir ++ "*")],
14+
file:del_dir(Dir).
15+
16+
17+
list_db(D) ->
18+
PI = <<"3.14159">>,
19+
E = <<"2.71828">>,
20+
elmdb:put(D, {"math", <<"pi">>}, PI),
21+
elmdb:put(D, {"math", <<"e">>}, E),
22+
[?_assertEqual(PI, elmdb:get(D, {"math", <<"pi">>})),
23+
?_assertEqual(E, elmdb:get(D, {"math", <<"e">>}))].
24+
25+
list_test_() ->
26+
[{"Try to list all dbs", {setup, fun startup/0, fun teardown/1, fun list_db/1}}].

0 commit comments

Comments
 (0)