Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tokio::test does not work with renamed crate (i.e. tokio02:::test) #2312

Closed
MOZGIII opened this issue Mar 10, 2020 · 3 comments · Fixed by #4613
Closed

tokio::test does not work with renamed crate (i.e. tokio02:::test) #2312

MOZGIII opened this issue Mar 10, 2020 · 3 comments · Fixed by #4613
Labels
A-tokio Area: The main tokio crate A-tokio-macros Area: The tokio-macros crate C-bug Category: This is a bug. E-help-wanted Call for participation: Help is requested to fix this issue.

Comments

@MOZGIII
Copy link
Contributor

MOZGIII commented Mar 10, 2020

Version

Long story short, we have:

tokio02 = { package = "tokio", version = "0.2.13", features = ["blocking", "fs", "sync", "macros", "test-util", "rt-core"] }
│   ├── tokio-codec v0.1.1
│   │   └── tokio-io v0.1.12
│   │   │   │   └── tokio-io v0.1.12 (*)
│   │   │   │   └── tokio-buf v0.1.1
│   │   │   ├── tokio v0.1.22
│   │   │   │   ├── tokio-codec v0.1.1 (*)
│   │   │   │   ├── tokio-current-thread v0.1.6
│   │   │   │   │   └── tokio-executor v0.1.9
│   │   │   │   ├── tokio-executor v0.1.9 (*)
│   │   │   │   ├── tokio-fs v0.1.6
│   │   │   │   │   ├── tokio-io v0.1.12 (*)
│   │   │   │   │   └── tokio-threadpool v0.1.17
│   │   │   │   │       └── tokio-executor v0.1.9 (*)
│   │   │   │   ├── tokio-io v0.1.12 (*)
│   │   │   │   ├── tokio-reactor v0.1.11
│   │   │   │   │   ├── tokio-executor v0.1.9 (*)
│   │   │   │   │   ├── tokio-io v0.1.12 (*)
│   │   │   │   │   └── tokio-sync v0.1.7
│   │   │   │   ├── tokio-sync v0.1.7 (*)
│   │   │   │   ├── tokio-tcp v0.1.3
│   │   │   │   │   ├── tokio-io v0.1.12 (*)
│   │   │   │   │   └── tokio-reactor v0.1.11 (*)
│   │   │   │   ├── tokio-threadpool v0.1.17 (*)
│   │   │   │   ├── tokio-timer v0.2.12
│   │   │   │   │   └── tokio-executor v0.1.9 (*)
│   │   │   │   ├── tokio-udp v0.1.5
│   │   │   │   │   ├── tokio-codec v0.1.1 (*)
│   │   │   │   │   ├── tokio-io v0.1.12 (*)
│   │   │   │   │   └── tokio-reactor v0.1.11 (*)
│   │   │   │   ├── tokio-uds v0.2.5
│   │   │   │   │   ├── tokio-codec v0.1.1 (*)
│   │   │   │   │   ├── tokio-io v0.1.12 (*)
│   │   │   │   │   └── tokio-reactor v0.1.11 (*)
│   │   │   ├── tokio-buf v0.1.1 (*)
│   │   │   ├── tokio-executor v0.1.9 (*)
│   │   │   ├── tokio-io v0.1.12 (*)
│   │   │   ├── tokio-reactor v0.1.11 (*)
│   │   │   ├── tokio-tcp v0.1.3 (*)
│   │   │   ├── tokio-threadpool v0.1.17 (*)
│   │   │   ├── tokio-timer v0.2.12 (*)
│   │   │   └── tokio-io v0.1.12 (*)
│   │   ├── tokio v0.1.22 (*)
│   │   ├── tokio-executor v0.1.9 (*)
│   │   ├── tokio-io v0.1.12 (*)
│   │   ├── tokio-threadpool v0.1.17 (*)
│   │   ├── tokio-timer v0.2.12 (*)
│   └── tokio-sync v0.1.7 (*)
│   ├── tokio-io v0.1.12 (*)
│   └── tokio-openssl v0.3.0
│       └── tokio-io v0.1.12 (*)
│   │   │   ├── tokio-process v0.2.4
│   │   │   │   ├── tokio-io v0.1.12 (*)
│   │   │   │   ├── tokio-reactor v0.1.11 (*)
│   │   │   │   └── tokio-signal v0.2.7
│   │   │   │       ├── tokio-executor v0.1.9 (*)
│   │   │   │       ├── tokio-io v0.1.12 (*)
│   │   │   │       └── tokio-reactor v0.1.11 (*)
│   │   │   └── tokio-timer v0.2.12 (*)
│   │   ├── tokio v0.1.22 (*)
│   │   ├── tokio-timer v0.2.12 (*)
│   │   ├── tokio v0.1.22 (*)
│   │   ├── tokio-io v0.1.12 (*)
│   │   └── tokio-uds v0.2.5 (*)
│   ├── tokio v0.1.22 (*)
│   ├── tokio-codec v0.1.1 (*)
│   ├── tokio-io v0.1.12 (*)
├── tokio v0.1.22 (*)
├── tokio v0.2.13
│   └── tokio-macros v0.2.5
├── tokio-compat v0.1.5
│   ├── tokio v0.2.13 (*)
│   ├── tokio-current-thread v0.1.6 (*)
│   ├── tokio-executor v0.1.9 (*)
│   ├── tokio-reactor v0.1.11 (*)
│   └── tokio-timer v0.2.12 (*)
├── tokio-retry v0.2.0
│   └── tokio-timer v0.2.12 (*)
├── tokio-signal v0.2.7 (*)
├── tokio-tls v0.2.1
│   └── tokio-io v0.1.12 (*)
├── tokio-uds v0.2.5 (*)
│   │   ├── tokio-executor v0.1.9 (*)
│   │   ├── tokio-sync v0.1.7 (*)
│   │   ├── tokio-sync v0.1.7 (*)
│   │   ├── tokio-timer v0.2.12 (*)
│   │   ├── tokio-timer v0.2.12 (*)
│   │   ├── tokio-timer v0.2.12 (*)
│       ├── tokio-io v0.1.12 (*)
│   │   └── tokio-tcp v0.1.3 (*)
│   ├── tokio-buf v0.1.1 (*)
│   ├── tokio-executor v0.1.9 (*)
│   ├── tokio-io v0.1.12 (*)
│   │   ├── tokio-buf v0.1.1 (*)
│   │   ├── tokio-io v0.1.12 (*)
│   ├── tokio v0.1.22 (*)
├── tracing-tower v0.1.0 (git+https://github.com/tokio-rs/tracing?rev=65547d8809fcc726b8187db85b23c42e32ef5dce#65547d8809fcc726b8187db85b23c42e32ef5dce)
│   └── tracing-futures v0.2.0 (git+https://github.com/tokio-rs/tracing?rev=65547d8809fcc726b8187db85b23c42e32ef5dce#65547d8809fcc726b8187db85b23c42e32ef5dce)
│   ├── tokio-executor v0.1.9 (*)
│   ├── tokio-io v0.1.12 (*)
│   ├── tokio-reactor v0.1.11 (*)
│   ├── tokio-tcp v0.1.3 (*)
│   ├── tokio-timer v0.2.12 (*)
│   ├── tokio-udp v0.1.5 (*)
│   ├── tokio v0.1.22 (*)
│   ├── tokio-executor v0.1.9 (*)
│   ├── tokio-tcp v0.1.3 (*)
│   ├── tokio-udp v0.1.5 (*)
    ├── tokio v0.1.22 (*)
    ├── tokio-io v0.1.12 (*)
    ├── tokio-threadpool v0.1.17 (*)
├── tokio-test v0.2.0
│   └── tokio v0.2.13 (*)
├── tokio01-test v0.1.1
│   ├── tokio-executor v0.1.9 (*)
│   └── tokio-timer v0.2.12 (*)
│   ├── tokio-sync v0.1.7 (*)
│   ├── tokio v0.1.22 (*)
│   ├── tokio-tcp v0.1.3 (*)
│   ├── tokio-udp v0.1.5 (*)
│   ├── tokio v0.1.22 (*)
│   ├── tokio-executor v0.1.9 (*)
│   ├── tokio-io v0.1.12 (*)
│   ├── tokio-reactor v0.1.11 (*)
│   ├── tokio-tcp v0.1.3 (*)
│   ├── tokio-timer v0.2.12 (*)
│   ├── tokio-udp v0.1.5 (*)

Description

If we do:

#[tokio02::test]
async fn qwe() {
     // ...
}

We get an error:

   | #[tokio02::test]
   | ^^^^^^^^^^^^^^^^ method not found in `tokio::runtime::threadpool::builder::Builder`

If we do:

use tokio02 as tokio;
#[tokio::test]
async fn qwe() {
     // ...
}

Everything works.

It's a small annoyance, and there's a workaround, but still...

@Darksonn Darksonn added A-tokio Area: The main tokio crate C-bug Category: This is a bug. E-help-wanted Call for participation: Help is requested to fix this issue. labels Apr 29, 2020
@LucioFranco
Copy link
Member

I believe this is related to rust-lang/rust#71259.

Last I checked on nightly this was fixed, so it would be good to test that.

@jebrosen
Copy link
Contributor

I believe the underlying cause of this is actually rust-lang/rust#54363: there is currently no way for tokio-macros to refer to "tokio 0.2, whatever it is named". There is also no workaround that does not require user involvement, such as the use above or a hypothetical #[tokio(crate = "tokio02")] like serde has implemented for its macros.

@RadicalZephyr
Copy link
Contributor

I took a first pass at implementing a crate option as @jebrosen describes, that commit is here.

However, I'm not sure that this option really makes any sense for these macros. As the documentation for the crate option in serde says, this kind of option is only really necessary in a very niche use-case. Since both the tokio::main and tokio::test macros are intended to be used in "application-style" situations (i.e. tests or a main function) where the code is not likely to be re-exported and used in another crate, the local workaround of renaming to tokio seems acceptable.

I think the best resolution for this is just to update the documentation for these macros to mention that renaming the tokio crate doesn't work with these macros.

@taiki-e taiki-e added the A-tokio-macros Area: The tokio-macros crate label May 20, 2020
kezhuw added a commit to kezhuw/tokio that referenced this issue Apr 11, 2022
This also enables `#[crate::test(package = "crate")]` in unit tests.

Sees rust-lang/cargo#5653.
Fixes tokio-rs#2312.
kezhuw added a commit to kezhuw/tokio that referenced this issue Apr 11, 2022
This also enables `#[crate::test(package = "crate")]` in unit tests.

Sees rust-lang/cargo#5653.
Fixes tokio-rs#2312.
kezhuw added a commit to kezhuw/tokio that referenced this issue Apr 12, 2022
This also enables `#[crate::test(package = "crate")]` in unit tests.

Sees rust-lang/cargo#5653.
Fixes tokio-rs#2312.
kezhuw added a commit to kezhuw/tokio that referenced this issue Apr 12, 2022
This also enables `#[crate::test(package = "crate")]` in unit tests.

Sees rust-lang/cargo#5653.
Fixes tokio-rs#2312.
kezhuw added a commit to kezhuw/tokio that referenced this issue Apr 13, 2022
This also enables `#[crate::test(package = "crate")]` in unit tests.

Sees rust-lang/cargo#5653.
Fixes tokio-rs#2312.
kezhuw added a commit to kezhuw/tokio that referenced this issue Apr 14, 2022
This also enables `#[crate::test(package = "crate")]` in unit tests.

Sees rust-lang/cargo#5653.
Fixes tokio-rs#2312.
kezhuw added a commit to kezhuw/tokio that referenced this issue Apr 15, 2022
This also enables `#[crate::test(package = "crate")]` in unit tests.

Sees rust-lang/cargo#5653.
Fixes tokio-rs#2312.
kezhuw added a commit to kezhuw/tokio that referenced this issue Apr 17, 2022
This also enables `#[crate::test(crate = "crate")]` in unit tests.

Sees rust-lang/cargo#5653.
Fixes tokio-rs#2312.
kezhuw added a commit to kezhuw/tokio that referenced this issue Apr 17, 2022
This also enables `#[crate::test(crate = "crate")]` in unit tests.

Sees rust-lang/cargo#5653.
Fixes tokio-rs#2312.
kezhuw added a commit to kezhuw/tokio that referenced this issue Apr 18, 2022
This also enables `#[crate::test(crate = "crate")]` in unit tests.

Sees rust-lang/cargo#5653.
Fixes tokio-rs#2312.
Darksonn pushed a commit that referenced this issue Apr 18, 2022
This also enables `#[crate::test(crate = "crate")]` in unit tests.

See: rust-lang/cargo#5653
Fixes: #2312
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate A-tokio-macros Area: The tokio-macros crate C-bug Category: This is a bug. E-help-wanted Call for participation: Help is requested to fix this issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants