| defmodule Plausible.Ingestion.WriteBufferTest do |
| use ExUnit.Case, async: true |
|
|
| import ExUnit.CaptureLog |
|
|
| alias Plausible.Ingestion.WriteBuffer |
|
|
| @compile_time_opts WriteBuffer.compile_time_prepare(Plausible.ClickhouseEventV2) |
|
|
| test "keeps running and logs the reason when a linked process exits", %{test: test} do |
| opts = [ |
| header: @compile_time_opts.header, |
| insert_sql: @compile_time_opts.insert_sql, |
| insert_opts: @compile_time_opts.insert_opts, |
| |
| name: test, |
| |
| flush_interval_ms: 1_000_000_000 |
| ] |
|
|
| {:ok, pid} = WriteBuffer.start_link(opts) |
|
|
| |
| |
| |
| |
| child = |
| spawn(fn -> |
| Process.link(pid) |
| Process.sleep(:infinity) |
| end) |
|
|
| ref = Process.monitor(child) |
|
|
| log = |
| capture_log(fn -> |
| Process.exit(child, :shutdown) |
| assert_receive {:DOWN, ^ref, :process, ^child, _}, 1_000 |
| assert Process.alive?(pid) |
| assert WriteBuffer.flush(test) == :ok |
| end) |
|
|
| assert log =~ "received EXIT, keeping buffer alive" |
| assert log =~ ":shutdown" |
| end |
| end |
|
|