What does `E RuntimeError: cannot re...
# plugins
b
What does
E               RuntimeError: cannot reuse already awaited coroutine
mean in a
run_rule_with_mocks
test? This is the only call to
run_rule_with_mocks
in this test
1
c
the error itself means that the coroutine has been re-used. will look that the linked file too…
b
It's copied and pasted from the other tests, which pass 😅
c
heh, yea, I don’t see anything fishy standing out at least 😛 running tests locally now see if I catch anything.. (do you repro locally too?)
mm… building pantsd…
yep, I repro locally.. digging…
Aha!, it’s the case with two union members, I suspect 😛
look at your for loop under test 😉
uhm, maybe… I had an idea.. need to confirm 😬
ah, yes.. I’ve not found the explanation yet, but the issue is that the run rule with mocks is not respecting the
StopIteration
thrown from your rule when it’s done.
b
Ohhhh interesting 🤔
c
Ah! the reason it’s not respecting is because there’s a bug in the test/code so you hit this mock:
Copy code
mock_gets=[
            MockGet(
                output_type=Digest,
                input_types=(URLDownloadHandler,),
                mock=lambda _: None,
            ),
and so, the return value from your rule is
None
, and the mock continues
b
It would've taken me a long time to figure that out lol
😝 1
c
this part here:
Copy code
except StopIteration as e:
            if e.args:
                return e.value  # type: ignore[no-any-return]
doesn’t return when you return
None
, and so doesn’t break the
while True
of the rule runner..
b
Ah it's supposed to be
and
not
or
😂
😂 1
c
I’d say, fix the mocks first, so you catch this issue properly before fixing 😉
But alas, I think the rule runner should throw an error if you get StopIteration without a None result. That’s bad.
b
Thank you!the mocks work. Really they should assert false, but assert is a statement
c
raise AssertionError(…)
b
That's also a statement
I'm lazy and want to use a lambda lol
c
hmm….
b
I mean an assert_false function works, I'll probably do that
c
Or, use a sentinel value…
b
Like None? 😅
c
Copy code
bad = object()
        digest = run_rule_with_mocks(
            download_file,
            rule_args=[
                DownloadFile("<http://pantsbuild.com/file.txt>", DOWNLOADS_FILE_DIGEST),
                union_membership,
            ],
            mock_gets=[
                MockGet(
                    output_type=Digest,
                    input_types=(URLDownloadHandler,),
                    mock=lambda _: bad,
                ),
                MockGet(
                    output_type=Digest,
                    input_types=(NativeDownloadFile,),
                    mock=lambda _: DOWNLOADS_EXPECTED_DIRECTORY_DIGEST,
                ),
            ],
            union_membership=union_membership,
        )
>       assert digest == DOWNLOADS_EXPECTED_DIRECTORY_DIGEST
E       AssertionError: assert equals failed
E         <object object at 0x1065ee870>                                                  Digest('4c9cf91fcd7ba1abbf7f9a0a1c8175556a82bee6a398e34db3284525ac24a3ad', 84)

src/python/pants/engine/download_file_integration_test.py:168: AssertionError
b
I got it from here. Thank you so much
👍 1
c
if you don’t mind filing another PR for the rule runner issue (throw error if rule returns None), I’d approve that 🙂
b