Skip to content

Commit 54f310d

Browse files
committed
feat testsuite: add sample and docs for uservice_oneshot
Tests: протестировано CI commit_hash:2e3bcf78374fb525511fd9bcf314f93ca53322c8
1 parent 80e09b3 commit 54f310d

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

samples/testsuite-support/tests/test_metrics.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import pytest
2+
3+
14
async def test_basic(service_client, monitor_client):
25
response = await service_client.get('/metrics')
36
assert response.status_code == 200
@@ -7,6 +10,14 @@ async def test_basic(service_client, monitor_client):
710
assert metric.value > 0
811

912

13+
# /// [uservice_oneshot sample]
14+
@pytest.mark.uservice_oneshot
15+
async def test_initial_metrics(service_client, monitor_client):
16+
metric = await monitor_client.single_metric('sample-metrics.foo')
17+
assert metric.value == 0
18+
# /// [uservice_oneshot sample]
19+
20+
1021
# /// [metrics reset]
1122
async def test_reset(service_client, monitor_client):
1223
# Reset service metrics

scripts/docs/en/userver/functional_testing.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,11 @@ In order to use it you need to register corresponding components:
195195

196196
Headers:
197197

198-
@snippet samples/testsuite-support/src/main.cpp testsuite - include components
198+
@snippet samples/testsuite-support/main.cpp testsuite - include components
199199

200200
Add components to components list:
201201

202-
@snippet samples/testsuite-support/src/main.cpp testsuite - register components
202+
@snippet samples/testsuite-support/main.cpp testsuite - register components
203203

204204
Add testsuite components to `config.yaml`:
205205

@@ -491,6 +491,21 @@ def test_service(service_client):
491491
...
492492
@endcode
493493

494+
@anchor uservice_oneshot
495+
#### uservice_oneshot testsuite tests
496+
497+
Testsuite allows to create tests that start a new service instance for the test and stop it on test finish:
498+
499+
@snippet samples/testsuite-support/tests/test_metrics.py uservice_oneshot sample
500+
501+
Such functionality slows down the tests run, but it may be required
502+
* to test service state right after the service start,
503+
* or to test that the service stops fine at some point,
504+
* or the test breaks the service for some time and restarting it is faster than waiting for recovery.
505+
506+
For per-daemon fixtures see @ref pytest_userver.plugins.service.daemon_scoped_mark "daemon_scoped_mark" fixture.
507+
508+
494509
----------
495510

496511
@htmlonly <div class="bottom-nav"> @endhtmlonly

scripts/docs/en/userver/roadmap_and_changelog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Changelog news also go to the
4848
to [akhoroshev](https://github.com/akhoroshev) for the PR!
4949
* Deadline Propagation for PostgreSQL is now enabled by default and can be controlled via `deadline-propagation-enabled`
5050
static option of the components::Postgres.
51-
* Testsuite now supports `@pytest.mark.uservice_oneshot`.
51+
* Testsuite now supports @ref uservice_oneshot "@pytest.mark.uservice_oneshot".
5252
* utils::regex now always uses a faster and safer Re2 instead of boost::regex.
5353
* Dynamic config `USERVER_HANDLER_STREAM_API_ENABLED` is not used any more.
5454
* server::handlers::HttpHandlerStatic now has a `expires` static config option.

0 commit comments

Comments
 (0)