Tests timing out - seems due to crate dependencies

tl,dr: The online tests time out, and I think it’s because I’m relying on an unexpected crate.

Suggestion: If the test runner can’t find the crates needed by the student’s code, or if any other weird issue happens during testing, make it easier for the student to see that something went wrong so they can ask for help.

First try

I wrote some code to solve the robot simulator exercise on the Rust track. That code uses the strum_macros crate. The tests pass on my machine, but then when I did

exercism submit src/lib.rs

the website said the tests failed. After some time clicking around, I found the test report with the following output:

We received the following error when we ran your code:

WARNING: student did not upload Cargo.lock. This may cause build errors.
   Compiling robot-simulator v2.2.0 (/mnt/exercism-iteration)
error[E0432]: unresolved import `strum_macros`
 --> src/lib.rs:1:5
  |
1 | use strum_macros::FromRepr;
  |     ^^^^^^^^^^^^ use of undeclared crate or module `strum_macros`

error: cannot determine resolution for the derive macro `FromRepr`
 --> src/lib.rs:4:45
  |
4 | #[derive(Clone, Copy, PartialEq, Eq, Debug, FromRepr)]
  |                                             ^^^^^^^^
  |
  = note: import resolution is stuck, try simplifying macro imports

error[E0599]: no variant or associated item named `from_repr` found for enum `Direction` in the current scope
  --> src/lib.rs:20:20
   |
5  | pub enum Direction {
   | ------------------ variant or associated item `from_repr` not found for this enum
...
20 |         Direction::from_repr(modulus(self as i8 + 1, 4) as usize).unwrap()
   |                    ^^^^^^^^^ variant or associated item not found in `Direction`

error[E0599]: no variant or associated item named `from_repr` found for enum `Direction` in the current scope
  --> src/lib.rs:23:20
   |
5  | pub enum Direction {
   | ------------------ variant or associated item `from_repr` not found for this enum
...
23 |         Direction::from_repr(modulus(self as i8 - 1, 4) as usize).unwrap()
   |                    ^^^^^^^^^ variant or associated item not found in `Direction`

Some errors have detailed explanations: E0432, E0599.
For more information about an error, try `rustc --explain E0432`.
error: could not compile `robot-simulator` due to 4 previous errors
warning: build failed, waiting for other jobs to finish...
error: could not compile `robot-simulator` due to 4 previous errors

I speculate that this could be too “advanced” for a beginner student to understand.

Second try

Based on this error message, I tried

exercism submit Cargo.lock src/lib.rs

but that still failed with a mostly similar error message, a difference being that the warning about not having uploaded Cargo.lock is not there.

Third try

On a guess I tried

exercism submit Cargo.toml Cargo.lock src/lib.rs

and got

We received the following error when we ran your code:

error: failed to select a version for the requirement `syn = "^1.0"` (locked to 1.0.105)
candidate versions found which didn't match: 1.0.104
location searched: `/opt/test-runner/local-registry` index (which is replacing registry `crates-io`)
required by package `strum_macros v0.24.3`
    ... which satisfies dependency `strum_macros = "*"` (locked to 0.24.3) of package `robot-simulator v2.2.0 (/mnt/exercism-iteration)`
perhaps a crate was updated and forgotten to be re-vendored?
As a reminder, you're using offline mode (--offline) which can sometimes cause surprising resolution failures, if this error is too confusing you may wish to retry without the offline flag.

Fourth try

I modified Cargo.toml to downgrade syn to 1.0.104, and resubmitted Cargo.lock, Cargo.toml, and src/lib.rs, and got the same error message as in the previous try.

Fifth try

I read the internet and found that to force syn to downgrade I have to use =1.0.104, so I did that and resubmitted. This time, the tests just time out.

Your tests timed out. This might mean that there was an issue in our infrastructure, but more likely it suggests that your code is running slowly. Is there an infinite loop or something similar?

Please check your code, and if nothing seems to be wrong, try running the tests again.

Here are the files (will upload src/lib.rs upon request, but I think it’s irrelevant):

Cargo.toml

[package]
edition = "2021"
name = "robot-simulator"
version = "2.2.0"

[dependencies]
strum_macros = "*"
syn = "=1.0.104"

Cargo.lock

# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3

[[package]]
name = "heck"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9"

[[package]]
name = "proc-macro2"
version = "1.0.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725"
dependencies = [
 "unicode-ident",
]

[[package]]
name = "quote"
version = "1.0.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179"
dependencies = [
 "proc-macro2",
]

[[package]]
name = "robot-simulator"
version = "2.2.0"
dependencies = [
 "strum_macros",
 "syn",
]

[[package]]
name = "rustversion"
version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97477e48b4cf8603ad5f7aaf897467cf42ab4218a38ef76fb14c2d6773a6d6a8"

[[package]]
name = "strum_macros"
version = "0.24.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59"
dependencies = [
 "heck",
 "proc-macro2",
 "quote",
 "rustversion",
 "syn",
]

[[package]]
name = "syn"
version = "1.0.104"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ae548ec36cf198c0ef7710d3c230987c2d6d7bd98ad6edc0274462724c585ce"
dependencies = [
 "proc-macro2",
 "quote",
 "unicode-ident",
]

[[package]]
name = "unicode-ident"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3"

Hi!

I’m not an expert in Rust nor I am involved in maintaining the Rust track, so see this post as an attempt to help with the things I know, but some information might not be 100% accurate and I’m happy to be corrected by someone more familiar with the Rust track.


The test runners run in docker containers with no network access. This means they aren’t able to download crates on the fly as needed.

However, the docker image ships with some dependencies in it, and you can use those. The list of supported crates is in this file: rust-test-runner/supported_crates at main · exercism/rust-test-runner · GitHub

strum_macros seems to be in there, but syn isn’t, which tells me you probably can’t use the syn crate. This list also doesn’t specify the versions of the dependencies, so I imagine it grabs the latest version for each one at the time the container is built. Not sure if there’s a way to know which version of each dependency is in the container, but it’s probably best to assume it’s not the latest available right now.

This also means that is probably best not to force specific versions in the Cargo.toml file, but maybe allow for a generous range of versions so the likelihood of the version included in the container being included in that range is higher.

When using external dependencies in Rust, I also don’t know if you need to submit your Cargo.lock, because it seems the lock file includes the result of doing version resolution locally and since you don’t know the versions on the container, dependency resolution locally might yield different results from the dependency resolution happening in the container. Maybe not submitting the Cargo.lock file is best?

1 Like

You are right. I removed the version pin on syn and uploaded only Cargo.toml and the code, and it worked :-)