{"id":23816769,"url":"https://github.com/dfaust/test-patience","last_synced_at":"2025-02-21T20:44:06.495Z","repository":{"id":57669559,"uuid":"80118334","full_name":"dfaust/test-patience","owner":"dfaust","description":"Synchronize the startup of applications that are part of an integration test","archived":false,"fork":false,"pushed_at":"2017-03-24T18:56:33.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-03T04:08:06.676Z","etag":null,"topics":["helper","integration-testing","rust"],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dfaust.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-MIT","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-26T13:48:46.000Z","updated_at":"2017-01-26T13:49:15.000Z","dependencies_parsed_at":"2022-09-26T20:40:31.039Z","dependency_job_id":null,"html_url":"https://github.com/dfaust/test-patience","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dfaust%2Ftest-patience","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dfaust%2Ftest-patience/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dfaust%2Ftest-patience/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dfaust%2Ftest-patience/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dfaust","download_url":"https://codeload.github.com/dfaust/test-patience/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240086455,"owners_count":19745822,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["helper","integration-testing","rust"],"created_at":"2025-01-02T04:32:15.177Z","updated_at":"2025-02-21T20:44:06.476Z","avatar_url":"https://github.com/dfaust.png","language":"Rust","readme":"# test-patience\n\n[![Build Status](https://travis-ci.org/dfaust/test-patience.svg?branch=master)](https://travis-ci.org/dfaust/test-patience)\n[![Windows build status](https://ci.appveyor.com/api/projects/status/github/dfaust/test-patience?svg=true)](https://ci.appveyor.com/project/dfaust/test-patience)\n[![Crate version](https://img.shields.io/crates/v/test-patience.svg)](https://crates.io/crates/test-patience)\n[![Documentation](https://img.shields.io/badge/documentation-docs.rs-df3600.svg)](https://docs.rs/test-patience)\n\ntest-patience is a utility to synchronize the startup of applications that are part of an integration test and the test itself.\n\nWhen writing integration tests, it is often necessary to launch applications that are part of the test.\nThis can take some time and if the test has to wait until the application is running, valuable time is lost when waiting for a fixed duration.\nAlso waiting for a fixed duration can still lead to test failures without producing a clear error message.\ntest-patience waits exactly until the starting application signals that it's ready or a specified timeout period has passed.\n\nThe test has to create an instance of the `Server` struct, which starts a TCP server and returns a port number.\nThat port number needs to be sent to the application that is needed to execute the test.\nThis could be done using an environment variable, an argument or a configuration file.\nAfter the start of the application has been initiated, the `wait` method needs to be called.\nIt blocks the currently running thread until either the starting application has signaled its successful start or the `timeout` period has passed.\n\nWhen the application is ready, it has to create an instance of the `Client` struct and call the `notify` method with the correct port number.\nAfter that the thread of the test continues executing.\n\nIn order to disable startup notifications in release builds, use `cfg!(debug_assertions)` (see [conditional compilation](https://doc.rust-lang.org/reference.html#conditional-compilation)).\n\n## Examples\n\nApplication\n\n```rust\nuse std::env;\n\n// initialize application (eg. connect to database server)\nlet db_connection = get_db_connection();\n\n// notify test in case the environment variable TEST_PATIENCE_PORT is set\nif let Some(port) = env::var(\"TEST_PATIENCE_PORT\").ok()\n                    .and_then(|s| s.parse::\u003cu16\u003e().ok()) {\n    test_patience::Client::notify(port).unwrap();\n}\n```\n\nTest\n\n```rust\nuse std::time::Duration;\nuse std::process;\n\nlet server = test_patience::Server::new().unwrap();\nlet port = server.port().unwrap();\n\nlet process = process::Command::new(\"path/to/application\")\n    .env(\"TEST_PATIENCE_PORT\", format!(\"{}\", port))\n    .spawn()\n    .unwrap();\n\nserver.wait(Duration::from_secs(5)).unwrap();\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdfaust%2Ftest-patience","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdfaust%2Ftest-patience","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdfaust%2Ftest-patience/lists"}