Skip to content

Commit

Permalink
Fixed flaky tests (lexical-lsp#252)
Browse files Browse the repository at this point in the history
These tests were failing occationally, and when I looked at them, they
were doing the wrong thing.
  • Loading branch information
scohen authored Jun 30, 2023
1 parent 11ea670 commit 2879d89
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 18 deletions.
3 changes: 2 additions & 1 deletion apps/plugin_runner/.formatter.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"],
import_deps: [:common]
]
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ defmodule Lexical.Plugin.Coordinator.StateTest do
assert State.failure_count(state, BadReturn) == 1
end

test "a plugin is disabled if it fails 3 times", %{state: state} do
test "a plugin is disabled if it fails 10 times", %{state: state} do
Runner.register(Crashes)

assert :crashes in Runner.enabled_plugins()
Expand Down
27 changes: 11 additions & 16 deletions apps/plugin_runner/test/lexical/plugin/runner/coordinator_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ defmodule Lexical.Runner.CoordinatorTest do
alias Lexical.Plugin.Runner
alias Lexical.Project

use ExUnit.Case
use ExUnit.Case, async: false
import Lexical.Test.EventualAssertions

setup do
{:ok, _} = start_supervised(Runner.Supervisor)
Expand Down Expand Up @@ -33,6 +34,10 @@ defmodule Lexical.Runner.CoordinatorTest do

def with_echo_plugin(_) do
Runner.register(Echo)

on_exit(fn ->
Runner.disable(Echo)
end)
end

def notifier do
Expand Down Expand Up @@ -113,6 +118,7 @@ defmodule Lexical.Runner.CoordinatorTest do
defp make_it_crash do
for _ <- 1..10 do
Runner.diagnose(%Document{}, notifier())
assert_receive _
end
end

Expand All @@ -121,6 +127,7 @@ defmodule Lexical.Runner.CoordinatorTest do

old_pid = Process.whereis(Runner.Coordinator)
assert :exits in Runner.enabled_plugins()

Runner.diagnose(%Document{}, notifier())

assert_receive [], 500
Expand All @@ -135,11 +142,7 @@ defmodule Lexical.Runner.CoordinatorTest do

make_it_crash()

assert_receive [], 500
assert_receive [], 500
assert_receive [], 500

refute :crashy in Runner.enabled_plugins()
refute_eventually :crashy in Runner.enabled_plugins()
end

test "slow plugins are disabled" do
Expand All @@ -149,11 +152,7 @@ defmodule Lexical.Runner.CoordinatorTest do

make_it_crash()

assert_receive []
assert_receive []
assert_receive []

refute :slow in Runner.enabled_plugins()
refute_eventually :slow in Runner.enabled_plugins()
end

test "plugins that don't return lists are disabled" do
Expand All @@ -163,11 +162,7 @@ defmodule Lexical.Runner.CoordinatorTest do

make_it_crash()

assert_receive [], 500
assert_receive [], 500
assert_receive [], 500

refute :bad_return in Runner.enabled_plugins()
refute_eventually :bad_return in Runner.enabled_plugins()
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ defmodule Lexical.RemoteControl.Build.StateTest do
{:ok, _} = start_supervised(Build.CaptureServer)
{:ok, _} = start_supervised(RemoteControl.ModuleMappings)
{:ok, _} = start_supervised(Lexical.Plugin.Runner.Coordinator)
{:ok, _} = start_supervised(Lexical.Plugin.Runner.Supervisor)
:ok
end

Expand Down

0 comments on commit 2879d89

Please sign in to comment.