Setup / teardown define tables between each test in the elixir?

We try to run each test in a completely clean dets environment, and each test is responsible for its own setup. We run into problems where we cannot completely delete a directory between tests.

How can we reset dets

? Did we incorrectly assume that you deleted the entire directory and relaunched the application, was the configuration enough? Is it better to delete all records between runs?

Let's assume:

  • async: true

    not installed for any tests.
  • dets

    required
  • Most of the response code should (if at all possible) be in the elixir, not erlang.

Sample code:

setup do
  #clean up anything that wasn't already clean (failed teardown, etc)
  TestSetup.teardown_dets(:myappatom, "dets")

  on_exit fn ->
    TestSetup.teardown_dets(:myappatom, "dets")
    Application.ensure_all_started(:myappatom)
    Process.sleep(300)
  end
end

      

And the gut functions rupture ...

def teardown_dets(application_atom, directory) when is_bitstring(directory) do
  teardown_dets(application_atom, [directory])
end
def teardown_dets(application_atom, directories)
  when is_atom(application_atom) and is_list(directories)
do
  #stop the applications completely
  Application.stop(application_atom)

  #blow away all dets while the application is stopped
  try do
    directories
    |> Enum.map(&File.rm_rf(&1))
  rescue
    error in File.Error -> IO.puts("First file removal failure. Re-attempting.  Initial error information #{error.message}")
  after
      Process.sleep(3000) #wait for whatever it was to get out of the way

      directories
      |> Enum.map(&File.rm_rf!(&1))
  end

end

      

Examples of startup errors are mix test

displayed on the screen:

dets: file "dets/event_listener_stream_positions_test" not properly closed, repairing ...

but not as a bug, just regular output to the console.

And then the actual failure in the test: ** (File.Error) could not remove files and directories recursively from "dets": file already exists

+3


source to share





All Articles