{"id":16678514,"url":"https://github.com/xoac/futures-test-sink","last_synced_at":"2026-05-12T16:37:12.362Z","repository":{"id":57632716,"uuid":"238720272","full_name":"xoac/futures-test-sink","owner":"xoac","description":"futures async/await sink tests helpers.","archived":false,"fork":false,"pushed_at":"2020-02-07T18:52:10.000Z","size":37,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-04-15T13:25:46.048Z","etag":null,"topics":["async","futures-rs","rust-lang","testing"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xoac.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-02-06T15:29:23.000Z","updated_at":"2020-02-08T02:22:02.000Z","dependencies_parsed_at":"2022-08-31T13:01:26.123Z","dependency_job_id":null,"html_url":"https://github.com/xoac/futures-test-sink","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/xoac/futures-test-sink","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xoac%2Ffutures-test-sink","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xoac%2Ffutures-test-sink/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xoac%2Ffutures-test-sink/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xoac%2Ffutures-test-sink/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xoac","download_url":"https://codeload.github.com/xoac/futures-test-sink/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xoac%2Ffutures-test-sink/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32948050,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-12T09:19:52.626Z","status":"ssl_error","status_checked_at":"2026-05-12T09:17:33.438Z","response_time":102,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["async","futures-rs","rust-lang","testing"],"created_at":"2024-10-12T13:29:32.193Z","updated_at":"2026-05-12T16:37:12.333Z","avatar_url":"https://github.com/xoac.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![crates.io](https://img.shields.io/crates/v/futures-test-sink.svg)](https://crates.io/crates/futures-test-sink)\n[![Documentation](https://docs.rs/futures-test-sink/badge.svg)](https://docs.rs/futures-test-sink/)\n![CI master](https://github.com/xoac/futures-test-sink/workflows/Continuous%20integration/badge.svg?branch=master)\n![Maintenance](https://img.shields.io/badge/maintenance-experimental-blue.svg)\n\n# futures-test-sink\n\nThis crate provide a handy mock sink implementations that can be used test own Sink.\n\n## Examples\n\n### `SinkMock` allow to create a handy tests\nThis example contains a 3 tests. See documentation of `SinkMock` for details.\n```rust\nuse futures::{\n    self,\n    never::Never,\n    stream::{self, StreamExt},\n};\nuse futures_test_sink::SinkMock;\nuse std::iter;\nuse std::task::{Context, Poll};\n\nfn drain_test() {\n    let e = iter::repeat::\u003cPoll\u003cResult\u003c(), Never\u003e\u003e\u003e(Poll::Ready(Ok(())));\n    let sink = SinkMock::with_flush_feedback(e);\n\n    let stream =\n        stream::iter(vec![Ok::\u003cu8, Never\u003e(5u8), Ok(7), Ok(9), Ok(77), Ok(79)].into_iter());\n    let send_all = stream.forward(sink);\n    assert_eq!(Ok(()), futures::executor::block_on(send_all));\n}\n\nfn interleave_pending() {\n    let e = vec![Poll::Ready(Ok::\u003c_, Never\u003e(())), Poll::Pending]\n        .into_iter()\n        .cycle();\n    let sink = SinkMock::with_flush_feedback(e);\n\n    let stream =\n        stream::iter(vec![Ok::\u003cu8, Never\u003e(5u8), Ok(7), Ok(9), Ok(77), Ok(79)].into_iter());\n    let send_all = stream.forward(sink);\n    assert_eq!(Ok(()), futures::executor::block_on(send_all));\n}\n\nfn error() {\n    let e = vec![Poll::Ready(Ok(())), Poll::Pending, Poll::Ready(Err(()))]\n        .into_iter()\n        .cycle();\n    let sink = SinkMock::with_flush_feedback(e);\n\n    let stream = stream::iter(vec![Ok(5u8), Ok(7), Ok(9), Ok(77), Ok(79)].into_iter());\n    let send_all = stream.forward(sink);\n    assert_eq!(Err(()), futures::executor::block_on(send_all));\n}\n\ndrain_test();\ninterleave_pending();\nerror();\n```\n\n### `SinkFeedback` mock provide a full control of returned items.\n\nYou should first use `SinkMock` if this doesn't this one may be useful.\n\n```rust\nuse async_task::waker_fn;\nuse futures::sink::Sink;\nuse futures_test_sink::from_iter;\nuse std::{\n    pin::Pin,\n    sync::{atomic, Arc},\n    task::{Context, Poll},\n};\n\n// create a Context\nlet wake_cnt = Arc::new(atomic::AtomicUsize::new(0));\nlet cnt = wake_cnt.clone();\nlet waker = waker_fn(move || {\n    wake_cnt.fetch_add(1, atomic::Ordering::SeqCst);\n});\nlet mut cx = Context::from_waker(\u0026waker);\n// actual test\nlet poll_fallback = vec![\n    Poll::Ready(Ok(())),\n    Poll::Ready(Ok(())),\n    Poll::Pending,\n    Poll::Ready(Err(12)),\n]\n.into_iter();\nlet start_send_fallback = vec![Ok::\u003c_, u32\u003e(())].into_iter().cycle();\n// ours sink implementation\nlet mut s = from_iter(poll_fallback, start_send_fallback);\n\nlet r1 = Pin::new(\u0026mut s).poll_ready(\u0026mut cx);\nassert_eq!(r1, Poll::Ready(Ok(())));\nlet s1 = Pin::new(\u0026mut s).start_send(1);\nassert_eq!(s1, Ok(()));\n\nlet r2 = Pin::new(\u0026mut s).poll_ready(\u0026mut cx);\nassert_eq!(r2, Poll::Ready(Ok(())));\n// start send don't panic because start_send_fallback is cycle\nlet s2 = Pin::new(\u0026mut s).start_send(2);\nassert_eq!(s2, Ok(()));\n\n// ctx.wake() wasn't called.\nassert_eq!(0, cnt.load(atomic::Ordering::SeqCst));\n\nlet r3 = Pin::new(\u0026mut s).poll_ready(\u0026mut cx);\nassert_eq!(r3, Poll::Pending);\nassert_eq!(1, cnt.load(atomic::Ordering::SeqCst));\n\nlet r4 = Pin::new(\u0026mut s).poll_ready(\u0026mut cx);\nassert_eq!(r4, Poll::Ready(Err(12)));\nassert_eq!(1, cnt.load(atomic::Ordering::SeqCst));\n```\n\nYou can be interested in [FuseLast](fuse_last::FuseLast) container for Iterator.\n\n\n```rust\nuse async_task::waker_fn;\nuse futures::sink::Sink;\nuse futures_test_sink::{from_iter, fuse_last::IteratorExt};\nuse std::{\n    pin::Pin,\n    sync::{atomic, Arc},\n    task::{Context, Poll},\n};\n\n// create a Context\nlet wake_cnt = Arc::new(atomic::AtomicUsize::new(0));\nlet cnt = wake_cnt.clone();\nlet waker = waker_fn(move || {\n    wake_cnt.fetch_add(1, atomic::Ordering::SeqCst);\n});\nlet mut cx = Context::from_waker(\u0026waker);\n// actual test\nlet poll_fallback = vec![\n    Poll::Ready(Ok(())),\n    Poll::Ready(Err(12)),\n    Poll::Ready(Ok(())),\n]\n.into_iter()\n.fuse_last();\nlet start_send_fallback = vec![Ok::\u003c_, u32\u003e(())].into_iter().cycle();\n// ours sink implementation\nlet mut s = from_iter(poll_fallback, start_send_fallback);\n\nlet r1 = Pin::new(\u0026mut s).poll_ready(\u0026mut cx);\nassert_eq!(r1, Poll::Ready(Ok(())));\nlet s1 = Pin::new(\u0026mut s).start_send(1);\nassert_eq!(s1, Ok(()));\n\nlet r2 = Pin::new(\u0026mut s).poll_ready(\u0026mut cx);\nassert_eq!(r2, Poll::Ready(Err(12)));\n\nlet r3 = Pin::new(\u0026mut s).poll_ready(\u0026mut cx);\nassert_eq!(r3, Poll::Ready(Ok(())));\n\n// if not `fuse_last` this would panic!\nlet r4 = Pin::new(\u0026mut s).poll_ready(\u0026mut cx);\nassert_eq!(r3, Poll::Ready(Ok(())));\n\nlet r5 = Pin::new(\u0026mut s).poll_ready(\u0026mut cx);\nassert_eq!(r3, Poll::Ready(Ok(())));\n```\n\n## License\n\nLicensed under either of\n\n * Apache License, Version 2.0\n   ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)\n * MIT license\n   ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)\n\nat your option.\n\n## Contribution\n\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in the work by you, as defined in the Apache-2.0 license, shall be\ndual licensed as above, without any additional terms or conditions.\n\nThis project try follow rules:\n* [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),\n* [Semantic Versioning](https://semver.org/spec/v2.0.0.html).\n\n_This README was generated with [cargo-readme](https://github.com/livioribeiro/cargo-readme) from [template](https://github.com/xoac/crates-io-lib-template)_\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxoac%2Ffutures-test-sink","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxoac%2Ffutures-test-sink","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxoac%2Ffutures-test-sink/lists"}