Skip to content

Commit 3dbf3e1

Browse files
committed
output of test units with capture_log minimized
1 parent 89b7a4b commit 3dbf3e1

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

test/mongo/connection_test.exs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ defmodule Mongo.ConnectionTest do
22
use MongoTest.Case, async: true
33
alias Mongo
44

5+
import ExUnit.CaptureLog
6+
57
defp connect do
68
assert {:ok, pid} =
79
Mongo.start_link(hostname: "localhost", database: "mongodb_test")
@@ -89,7 +91,7 @@ defmodule Mongo.ConnectionTest do
8991
assert capture_log(fn ->
9092
{:ok, pid} = Mongo.start_link(opts)
9193
assert_receive {:EXIT, ^pid, :killed}, 5000
92-
end)
94+
end) =~ "(Mongo.Error) auth failed for user mongodb_admin_user"
9395
end
9496

9597
test "insert_one flags" do
@@ -176,15 +178,17 @@ defmodule Mongo.ConnectionTest do
176178
end
177179

178180
test "auth connection leak" do
179-
# sometimes the function tcp_count() returns 1, so the test fails.
180-
# maybe it is a good idea to wait a second before counting
181-
:timer.sleep(1000)
182-
assert tcp_count() == 0
183-
Enum.each(1..10, fn _ ->
184-
connect_auth_invalid()
181+
assert capture_log(fn ->
182+
# sometimes the function tcp_count() returns 1, so the test fails.
183+
# maybe it is a good idea to wait a second before counting
184+
:timer.sleep(1000)
185+
assert tcp_count() == 0
186+
Enum.each(1..10, fn _ ->
187+
connect_auth_invalid()
188+
end)
189+
:timer.sleep(1000)
190+
# there should be 10 connections with connection_type: :monitor
191+
assert tcp_count() == 10
185192
end)
186-
:timer.sleep(1000)
187-
# there should be 10 connections with connection_type: :monitor
188-
assert tcp_count() == 10
189193
end
190194
end

test/test_helper.exs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,6 @@ defmodule MongoTest.Case do
4747
end
4848
end
4949

50-
def capture_log(fun) do
51-
Logger.remove_backend(:console)
52-
fun.()
53-
Logger.add_backend(:console, flush: true)
54-
end
55-
5650
defmacro unique_name do
5751
{function, _arity} = __CALLER__.function
5852
"#{__CALLER__.module}.#{function}"

0 commit comments

Comments
 (0)