test threads for cargo (rust)

spam.wax's Avatar


15 May, 2018 09:11 PM

I need to make sure that cargo runs my tests sequentially by passing --test-threads=1 to the test runner executable.

Locally I can do this using

cargo test -- --test-threads=1

However, it seems having that line in my test_script section doesn't work. It seems the double-dash is ignored.

How do I make sure that above command is run correctly?
Here is the link to my appveyor.yml file

  1. Support Staff 1 Posted by Ilya Finkelshte... on 16 May, 2018 01:54 AM

    Ilya Finkelshteyn's Avatar

    Sorry for confusion. While PowerShell blocks runs as a single script, CMD runs line-by-line. Workaround is to wrap the whole script in .cmd file and run that file.

  2. 2 Posted by spam.wax on 16 May, 2018 02:45 AM

    spam.wax's Avatar

    I'm not sure how to do this exactly!
    Do I have to create a .CMD in my repo and somehow call it from yml script?
    What would be the content of that file to ensure sequential run and how do
    I call it from yml?

  3. Support Staff 3 Posted by Ilya Finkelshte... on 16 May, 2018 02:55 AM

    Ilya Finkelshteyn's Avatar

    Yes, you can check-in .cmd in repo. But in your case indeed it is simple to use one-liner like this:

      - if [%APPVEYOR_REPO_TAG%]==[false] (cargo test --target %TARGET% --lib -- --test-threads=1)

    Let us know if this works for you.

  4. 4 Posted by spam.wax on 16 May, 2018 03:07 AM

    spam.wax's Avatar

    I already had that line in test_script section.
    I even put the whole thing in one line as suggested but still tests are run concurrently.

    my current appveyor.yml

  5. Support Staff 5 Posted by Ilya Finkelshte... on 16 May, 2018 06:25 AM

    Ilya Finkelshteyn's Avatar

    Your appveyor.yml (at least at the moment), uses - sh prefix for that command, which makes sense only for Linux builds (if you choose Ubuntu image). But you probably already realized that.

    I do not believe that double-dash is ignored. You can RDP to build VM and run command manually and you will probably see the same result.

    I am not Rust expect by any means, but here and here people say that --test-threads=1 specifies number of addition thread, not total number of threads.

    I would try to understand the difference between local run and AppVeyor run.

    • Do you have the same errors locally if you do not specify --test-threads=1 and they disappear if you specify that?

    • Do you have the same Rust version locally and on AppVeyor?

    • How many CPU cores you have locally? AppVeyor VM has 2. Number of CPU cores can affect parallelism.

  6. 6 Posted by spam.wax on 16 May, 2018 06:37 AM

    spam.wax's Avatar

    Thanks for your response

    Yea, I had been changing it from cmd to ps to pwsh and to sh just to get the thing working!
    That's correct, the main thread is in charge of running each new thread assigned to a specific test.

    • I do not get any error when --test-threads=1 locally. Not having it actually causes errors which are different every time. The web-server mocker in tests only listens on port 1234 and if multiple tests are run it will cause issue since it has a fixed response.

    • Yes, I have tested it with multiple versions as well

    • I have 6 cores at my local machine

    How can I echo the command that test_script actually calls/runs?

    And in what env./shell the .yml runs/launches its command?

  7. Support Staff 7 Posted by Ilya Finkelshte... on 17 May, 2018 03:53 AM

    Ilya Finkelshteyn's Avatar

    CMD is being called by build agent (.NET program) using native interop calls. What you see in the line before command like here is exact echo of what is going to be called.

    RDP to build VM and run command manually so you can rule out the fact that command is being called by build agent. Please note that RDP session does not have the same environment variables as build session, so you need to re-create environment variables which are critical for this command execution.

    Let us know what you found.

  8. Ilya Finkelshteyn closed this discussion on 25 Aug, 2018 02:28 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac