Настроить / разорвать таблицы dets между каждым тестом в эликсире?
Мы пытаемся запустить каждый тест в абсолютно чистой среде, и каждый тест отвечает за свои собственные настройки. Мы сталкиваемся с проблемами, когда мы не можем полностью удалить каталог между тестами.
Как мы можем сбросить dets
? Неправильно ли мы предполагали, что удаление всей директории и перезапуск приложения были достаточной настройкой? Лучше удалить все записи между прогонами?
Предполагать:
async: true
не установлен для каких-либо тестов.dets
необходимо- Большая часть кода ответа (если это вообще возможно) должна быть в эликсире, а не в эрланге.
Пример кода:
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
И кишки функции демонтажа...
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
Пример ошибок при запуске mix test
стандартный вывод:
dets: file "dets/event_listener_stream_positions_test" not properly closed, repairing ...
но не как ошибка, просто обычный вывод на консоль.
И тогда фактический сбой в тесте:** (File.Error) could not remove files and directories recursively from "dets": file already exists