<commit_before>-module(sd_notify_test).

-include_lib("eunit/include/eunit.hrl").


sd_notify_test_() ->
	sd_notify_test_local(erlang:system_info(otp_release)).

sd_notify_test_local("19") ->
	{ok, CWD} = file:get_cwd(),
	FakeNotifyUnixSockName = CWD ++ "/fake-notify-udp-sock-" ++ integer_to_list(erlang:phash2(make_ref())),
	TestMessage = integer_to_list(erlang:phash2(make_ref())),
	{ok, FakeNotifyUnixSock} = gen_udp:open(0, [{ifaddr, {local, FakeNotifyUnixSockName}}, {active, false}, list]),
	os:putenv("NOTIFY_SOCKET", FakeNotifyUnixSockName),

	{setup,
		fun() -> ok end,
		fun(_) -> ok = gen_udp:close(FakeNotifyUnixSock), ok = file:delete(FakeNotifyUnixSockName)  end,
		[
			{
				"Try sending message",
				fun() ->
					sd_notify:sd_pid_notify_with_fds(0, 0, TestMessage, [1, 2, 3]),
					{ok, {_Address, _Port, Packet}} = gen_udp:recv(FakeNotifyUnixSock, length(TestMessage), 1000),
					?assertEqual(TestMessage, Packet)
				end
			}

		]

	};
sd_notify_test_local(_) ->
	[].<commit_msg>Move test message creation to where it belongs<commit_after>-module(sd_notify_test).

-include_lib("eunit/include/eunit.hrl").


sd_notify_test_() ->
	sd_notify_test_local(erlang:system_info(otp_release)).

sd_notify_test_local("19") ->
	{ok, CWD} = file:get_cwd(),
	FakeNotifyUnixSockName = CWD ++ "/fake-notify-udp-sock-" ++ integer_to_list(erlang:phash2(make_ref())),
	{ok, FakeNotifyUnixSock} = gen_udp:open(0, [{ifaddr, {local, FakeNotifyUnixSockName}}, {active, false}, list]),
	os:putenv("NOTIFY_SOCKET", FakeNotifyUnixSockName),

	{setup,
		fun() -> ok end,
		fun(_) -> ok = gen_udp:close(FakeNotifyUnixSock), ok = file:delete(FakeNotifyUnixSockName)  end,
		[
			{
				"Try sending message",
				fun() ->
					TestMessage = integer_to_list(erlang:phash2(make_ref())),
					sd_notify:sd_pid_notify_with_fds(0, 0, TestMessage, [1, 2, 3]),
					{ok, {_Address, _Port, Packet}} = gen_udp:recv(FakeNotifyUnixSock, length(TestMessage), 1000),
					?assertEqual(TestMessage, Packet)
				end
			}

		]

	};
sd_notify_test_local(_) ->
	[].
{'fraction_non_alphanumeric': 0.16658500734933857, 'fraction_numerical': 0.013718765311121999, 'mean_word_length': 5.38125, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '480210', 'n_tokens_mistral': 906, 'n_tokens_neox': 797, 'n_words': 119}