Skip to content

Conversation

@asosnoviy
Copy link
Contributor

@asosnoviy asosnoviy commented Dec 12, 2025

Summary by CodeRabbit

  • Tests
    • Enhanced test infrastructure with explicit global startup/shutdown sequencing and test-mode environment setup.
    • Added object creation initialization and per-test setup/teardown hooks that save/restore state.
    • Implemented service launch/stop orchestration and readiness checks before running tests.
    • Added guards to abort tests if prerequisites aren't met and ensured cleanup cancels running test services.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 12, 2025

Walkthrough

Adds exported test lifecycle hooks and object-initialization stubs across two test suites to start/stop an HttpBin service, set an environment flag, and preserve/restore per-test environment state.

Changes

Cohort / File(s) Summary
HttpBin API test lifecycle
tests/HttpBin_API_test.os
Adds a test set with characteristic "Одиночка"; adds ПриСозданииОбъекта() stub; adds exported lifecycle procedures ПередЗапускомТестов(), ПослеЗапускомТестов(), and ПередЗапускомТеста(); ПередЗапускомТестов() initializes and launches HttpBin with env HTTPBIN_IS_TEST_MODE=true; teardown stops HttpBin.
HttpBin tests and per-test state management
tests/HttpBin_test.os
Adds test set "Одиночка"; adds ПриСозданииОбъекта() stub; exports ПередЗапускомТеста() (saves current directory) and ПослеЗапускомТеста() (restores directory and stops HttpBin if running); integrates per-test guards and cleanup into existing tests.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–30 minutes

  • Inspect HttpBin start/stop calls and environment variable injection in ПередЗапускомТестов() / ПослеЗапускомТестов().
  • Verify exported procedure signatures and visibility match test runner expectations.
  • Confirm directory save/restore logic and conditional HttpBin shutdown in per-test teardown are robust against concurrent or failed launches.

Possibly related PRs

Poem

🐰
Встал я утром, хлоп — тесты в ряд,
Хоп — запустил HttpBin для парада.
Перед, После — порядок впорядке,
Я хрюкаю радостно: всё в порядке! 🥕

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Подгон тестов под oneunit' directly describes the main objective of the PR - adapting/adjusting tests to work with the oneunit testing framework by adding lifecycle hooks and test initialization procedures.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
tests/HttpBin_API_test.os (1)

17-41: Harden lifecycle hooks: guard Остановить() and strengthen “service is running” checks.
Right now ПослеЗапускаТестов() unconditionally calls HttpBin.Остановить() (can throw if ПередЗапускомТестов() failed early / HttpBin is Неопределено). Also ПередЗапускомТеста() only checks СервисЗапущен, which can drift from reality.

 &ПослеВсех
 Процедура ПослеЗапускаТестов() Экспорт
-	HttpBin.Остановить();
+	Если HttpBin <> Неопределено Тогда
+		HttpBin.Остановить();
+	КонецЕсли;
+	СервисЗапущен = Ложь;
 КонецПроцедуры

 &ПередКаждым
 Процедура ПередЗапускомТеста() Экспорт
-	Если Не СервисЗапущен Тогда
+	Если Не СервисЗапущен Или HttpBin = Неопределено Тогда
 		ВызватьИсключение "Сервис не запущен";
 	КонецЕсли;
 КонецПроцедуры

Also consider restoring HTTPBIN_IS_TEST_MODE in ПослеЗапускаТестов() to avoid leaking state into other suites.

tests/HttpBin_test.os (2)

11-30: Avoid double-stop and keep _HttpBin state consistent in ПослеЗапускаТеста().
ПослеЗапускаТеста() stops _HttpBin but doesn’t clear it; plus one test stops it manually, so teardown may stop twice.

 &ПослеКаждого
 Процедура ПослеЗапускаТеста() Экспорт
 	
 	УстановитьТекущийКаталог(_ТекущийКаталог);

 	Если Не _HttpBin = Неопределено Тогда
 		_HttpBin.Остановить();
+		_HttpBin = Неопределено;
 	КонецЕсли;

 КонецПроцедуры

43-64: Async-start test is flaky: replace time-based sleeps with “wait until отвечает() (with timeout)”.
Using ВремяЗапуска from a prior run + Приостановить(ВремяЗапуска) will intermittently fail on CI variance; also you currently stop _HttpBin in-test and then teardown stops again unless you clear _HttpBin.

 Процедура ТестДолжен_ЗапуститьСервисАсинхронноИОстановить() Экспорт
@@
 	_HttpBin.Запустить();
@@
-	_HttpBin.Остановить();
+	_HttpBin.Остановить();
+	_HttpBin = Неопределено; // чтобы teardown не пытался остановить повторно
@@
 	// Действие
 	_HttpBin.ЗапуститьАсинх();
-
-	Приостановить(ВремяЗапуска);
+	// TODO: дождаться запуска (poll) с таймаутом, вместо sleep по прошлому времени

 	// Проверка
 	Ожидаем.Что(_HttpBin.Отвечает(), "Должен быть запущен").ЭтоИстина();

(Я бы вынес общий helper ДождатьсяЗапускаHttpBin(_HttpBin, ТаймаутМс) и переиспользовал его.)

🧹 Nitpick comments (1)
tests/HttpBin_API_test.os (1)

12-15: Empty ПриСозданииОбъекта() looks redundant—either remove or add a brief comment why it’s required by oneunit.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e6ac8e4 and 75fa82b.

📒 Files selected for processing (2)
  • tests/HttpBin_API_test.os (2 hunks)
  • tests/HttpBin_test.os (1 hunks)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
tests/HttpBin_API_test.os (1)

31-34: Consider adding a guard before stopping the service.

If ПередЗапускомТестов() fails before HttpBin is assigned (e.g., exception during initialization), calling HttpBin.Остановить() could fail. The pattern in HttpBin_test.os (line 26-28) checks Если Не _HttpBin = Неопределено before stopping.

 &ПослеВсех
 Процедура ПослеЗапускаТестов() Экспорт
+	Если Не HttpBin = Неопределено Тогда
 		HttpBin.Остановить();
+	КонецЕсли;
 КонецПроцедуры
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 75fa82b and 7580ad9.

📒 Files selected for processing (2)
  • tests/HttpBin_API_test.os (2 hunks)
  • tests/HttpBin_test.os (1 hunks)
🔇 Additional comments (6)
tests/HttpBin_test.os (3)

11-14: LGTM: Test set annotation and object initialization stub.

The &ТестовыйНабор(Характер = "Одиночка") annotation correctly marks this as a singleton test set for oneunit. The empty ПриСозданииОбъекта() procedure is an appropriate stub required by the framework.


16-19: LGTM: Per-test setup hook.

The &ПередКаждым annotation correctly marks the existing setup procedure for per-test execution. Saving the current directory before each test enables proper cleanup.


21-30: LGTM: Per-test teardown hook.

The &ПослеКаждого annotation and teardown logic are correct. The procedure properly restores the working directory and conditionally stops the HttpBin service if it was initialized.

tests/HttpBin_API_test.os (3)

12-15: LGTM: Test set annotation and object initialization stub.

Consistent with the pattern in HttpBin_test.os.


17-29: LGTM: Global test setup.

The &ПередВсеми hook correctly initializes the HttpBin service once for all tests and sets the test mode environment variable. The СервисЗапущен flag provides state tracking for the per-test guard.


36-41: LGTM: Per-test service availability guard.

The &ПередКаждым hook properly checks if the service started successfully and throws a clear exception if not, preventing confusing failures in individual tests.

@Stivo182 Stivo182 merged commit 67ee641 into Stivo182:main Dec 12, 2025
2 of 7 checks passed
@Stivo182
Copy link
Owner

Спасибо!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants