diff --git a/tests/integration/test_startup_scripts_execution_state/__init__.py b/tests/integration/test_startup_scripts_execution_state/__init__.py
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/tests/integration/test_startup_scripts_execution_state/config/bad_script.xml b/tests/integration/test_startup_scripts_execution_state/config/bad_script.xml
new file mode 100644
index 00000000000..1306cc116c9
--- /dev/null
+++ b/tests/integration/test_startup_scripts_execution_state/config/bad_script.xml
@@ -0,0 +1,10 @@
+
+
+
+ SELECT 42;
+
+
+ SELECT * FROM non_existent_table;
+
+
+
diff --git a/tests/integration/test_startup_scripts_execution_state/config/good_script.xml b/tests/integration/test_startup_scripts_execution_state/config/good_script.xml
new file mode 100644
index 00000000000..f16f800eb6c
--- /dev/null
+++ b/tests/integration/test_startup_scripts_execution_state/config/good_script.xml
@@ -0,0 +1,11 @@
+
+
+
+ SELECT 0;
+ SELECT * FROM non_existent_table;
+
+
+ SELECT 42;
+
+
+
diff --git a/tests/integration/test_startup_scripts_execution_state/config/users.xml b/tests/integration/test_startup_scripts_execution_state/config/users.xml
new file mode 100644
index 00000000000..c5de0b6819c
--- /dev/null
+++ b/tests/integration/test_startup_scripts_execution_state/config/users.xml
@@ -0,0 +1,8 @@
+
+
+
+ default
+
+
+
+
\ No newline at end of file
diff --git a/tests/integration/test_startup_scripts_execution_state/test.py b/tests/integration/test_startup_scripts_execution_state/test.py
new file mode 100644
index 00000000000..e379a7bf0aa
--- /dev/null
+++ b/tests/integration/test_startup_scripts_execution_state/test.py
@@ -0,0 +1,56 @@
+from enum import Enum
+import random
+import string
+import time
+
+import pytest
+
+from helpers.cluster import ClickHouseCluster
+
+cluster = ClickHouseCluster(__file__)
+good = cluster.add_instance(
+ "good",
+ main_configs=[
+ "config/users.xml",
+ "config/good_script.xml"
+ ],
+ stay_alive=True,
+)
+bad = cluster.add_instance(
+ "bad",
+ main_configs=[
+ "config/users.xml",
+ "config/bad_script.xml"
+ ],
+ stay_alive=True,
+)
+
+
+@pytest.fixture(scope="module")
+def start_cluster():
+ try:
+ cluster.start()
+ yield cluster
+ finally:
+ cluster.shutdown()
+
+
+def test_startup_execution_state(start_cluster):
+ """
+ Making sure that the StartupScriptsExecutionState metric is set correctly.
+ """
+
+ STATE_SUCCESS = 1
+ STATE_FAILURE = 2
+
+ assert int(
+ good.query(
+ "SELECT value FROM system.metrics WHERE metric = 'StartupScriptsExecutionState'"
+ ).strip()
+ ) == STATE_SUCCESS
+
+ assert int(
+ bad.query(
+ "SELECT value FROM system.metrics WHERE metric = 'StartupScriptsExecutionState'"
+ ).strip()
+ ) == STATE_FAILURE
diff --git a/tests/queries/0_stateless/03277_startup_scripts_state_ok.reference b/tests/queries/0_stateless/03277_startup_scripts_state_ok.reference
deleted file mode 100644
index d00491fd7e5..00000000000
--- a/tests/queries/0_stateless/03277_startup_scripts_state_ok.reference
+++ /dev/null
@@ -1 +0,0 @@
-1
diff --git a/tests/queries/0_stateless/03277_startup_scripts_state_ok.sql b/tests/queries/0_stateless/03277_startup_scripts_state_ok.sql
deleted file mode 100644
index b32241d74ab..00000000000
--- a/tests/queries/0_stateless/03277_startup_scripts_state_ok.sql
+++ /dev/null
@@ -1 +0,0 @@
-SELECT value FROM system.metrics WHERE metric = 'StartupScriptsExecutionState'