epgsql_perf_SUITE.erl 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. -module(epgsql_perf_SUITE).
  2. -include_lib("common_test/include/ct.hrl").
  3. -include_lib("eunit/include/eunit.hrl").
  4. -export([
  5. init_per_suite/1,
  6. all/0,
  7. end_per_suite/1,
  8. prepare_data/0,
  9. prepare_data/1,
  10. get_data/0,
  11. get_data/1,
  12. drop_data/1
  13. ]).
  14. init_per_suite(Config) ->
  15. Config.
  16. end_per_suite(_Config) ->
  17. ok.
  18. all() ->
  19. [
  20. prepare_data,
  21. get_data,
  22. drop_data
  23. ].
  24. %% =============================================================================
  25. %% Test cases
  26. %% =============================================================================
  27. -define(noise_size, 10000000).
  28. prepare_data() -> [{timetrap, {seconds, 60}}].
  29. prepare_data(Config) ->
  30. with_connection(Config, fun (C) ->
  31. Noise = noise(?noise_size),
  32. {ok, [], []} = epgsql:squery(C, "create table test_big_blobs (id int4 primary key, noise bytea)"),
  33. {ok, 1} = epgsql:equery(C, "insert into test_big_blobs (id, noise) values (1, $1)", [Noise])
  34. end).
  35. get_data() -> [{timetrap, {seconds, 60}}].
  36. get_data(Config) ->
  37. with_connection(Config, fun (C) ->
  38. {ok, _, [{Noise}]} = epgsql:equery(C, "select noise from test_big_blobs"),
  39. ?assertEqual(?noise_size, byte_size(Noise))
  40. end).
  41. drop_data(Config) ->
  42. with_connection(Config, fun (C) ->
  43. {ok, [], []} = epgsql:squery(C, "drop table test_big_blobs")
  44. end).
  45. %% =============================================================================
  46. %% Internal functions
  47. %% =============================================================================
  48. noise(N) ->
  49. crypto:strong_rand_bytes(N).
  50. with_connection(Config, F) ->
  51. with_connection(Config, F, "epgsql_test", []).
  52. with_connection(Config, F, Username, Args) ->
  53. {Host, Port} = epgsql_ct:connection_data(Config),
  54. Args2 = [{port, Port}, {database, "epgsql_test_db1"} | Args],
  55. fun () ->
  56. {ok, C} = epgsql:connect(Host, Username, Args2),
  57. try
  58. F(C)
  59. after
  60. epgsql:close(C)
  61. end
  62. end.