Skip to content

Commit

Permalink
t_sqlexpr_sqlite: don't use :memory: db for nested iter/fold tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
mfp committed Jan 25, 2011
1 parent 2d85a1d commit 79334d0
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions t_sqlexpr_sqlite.ml
Expand Up @@ -28,12 +28,17 @@ struct
assert_equal
~printer:(fun l -> "[ " ^ String.concat "; " (List.map printer l) ^ " ]")

let with_db f x =
let db = S.open_db ":memory:" in
(* schema changes to :memory: db made by a Sqlexpr_sqlite_lwt worker are not
* seen by the others, so allow to use a file by doing ~in_mem:false *)
let with_db ?(in_mem = true) f x =
let file =
if in_mem then ":memory:" else Filename.temp_file "t_sqlexpr_sqlite_" "" in
let db = S.open_db file in
try_lwt
f db x
finally
S.close_db db;
if not in_mem then Sys.remove file;
return ()

let test_execute () =
Expand Down Expand Up @@ -208,7 +213,10 @@ struct
end ()

let test_nested_iter_and_fold () =
with_db begin fun db () ->
(* nested iter/folds will spawn multiple Sqlexpr_sqlite_lwt workers, so
* cannot use in-mem DB, lest the table not be created in other workers
* than the one where it was created *)
with_db ~in_mem:false begin fun db () ->
S.execute db sql"CREATE TABLE foo(n INTEGER NOT NULL)" >>
iter (S.execute db sqlc"INSERT INTO foo(n) VALUES(%d)") [1; 2; 3] >>
let q = Queue.create () in
Expand Down

0 comments on commit 79334d0

Please sign in to comment.