Make Perforce tests use a local p4d.

Review Request #14546 — Created Aug. 1, 2025 and submitted

Information

Review Board
release-7.x

Reviewers

Very early on, we wrote unit tests for the perforce implementation that
connected to public.perforce.com:1666. This worked okay for most things,
but it always felt kind of wrong.

This change makes it so we'll instead spin up a local p4d. This works
for almost all of our tests, and the slight delay I had to add during
that spin-up process is offset by no longer having to make actual
requests to the internet.

It seems like something in the Perforce tests was actually making a lot
of the Perforce tests run successfully even if they were broken. I'm not
sure which of my changes uncovered it, but there were several tests for
revision parsing which were obsolete (since revision parsing moved
completely into the diff parser). I've just removed those tests.

reviewboard/scmtools/testdata/p4_repo is part of the commit but has
been excluded from the posted change.

Ran all perforce tests and saw that all of them actually ran, and that
the previously broken stunnel tests now passed.

Summary ID
Make Perforce tests use a local p4d.
Very early on, we wrote unit tests for the perforce implementation that connected to public.perforce.com:1666. This worked okay for most things, but it always felt kind of wrong. This change makes it so we'll instead spin up a local p4d. This works for almost all of our tests, and the slight delay I had to add during that spin-up process is offset by no longer having to make actual requests to the internet. It seems like something in the Perforce tests was actually making a lot of the Perforce tests run successfully even if they were broken. I'm not sure which of my changes uncovered it, but there were several tests for revision parsing which were obsolete (since revision parsing moved completely into the diff parser). I've just removed those tests. Testing Done: Ran all perforce tests and saw that all of them actually ran, and that the previously broken stunnel tests now passed.
a4e95cec8c3c5be0e97ba78393477fa2a6158c95
Description From Last Updated

too many blank lines (2) Column: 5 Error code: E303

reviewbotreviewbot

I think what you can do here is to update the if above to do: if P4 is not None …

chipx86chipx86

Worried this is going to be an issue on the CI server, which has a tendency to trip up timing-related …

chipx86chipx86

Leftover debug statements.

chipx86chipx86

Might be worth seeing how much work it'd be to remote-control something for this, but maybe not worth it. Though …

chipx86chipx86

Can we pick a different port? 1666 being the default port will conflict with actual local usage. How about something …

chipx86chipx86
Checks run (1 failed, 1 succeeded)
flake8 failed.
JSHint passed.

flake8

david
chipx86
  1. You're awesome.

  2. Show all issues

    I think what you can do here is to update the if above to do:

    if P4 is not None or TYPE_CHECKING:
        ...
    

    That should it from even considering the possibility of this code path.

    1. That hits the same problem with unreachable code detection as we've previously discussed.

  3. reviewboard/scmtools/tests/test_perforce.py (Diff revision 2)
     
     
     
    Show all issues

    Worried this is going to be an issue on the CI server, which has a tendency to trip up timing-related things like this.

    Instead (or, along with), can we have it try N times to perform some query and then sleep 0.1 between them?

    That'll also be a good place to provide a suitable error if we can't do that connection, so it doesn't fall into the tests.

  4. reviewboard/scmtools/tests/test_perforce.py (Diff revision 2)
     
     
     
     
     
     
     
     
    Show all issues

    Leftover debug statements.

  5. reviewboard/scmtools/tests/test_perforce.py (Diff revision 2)
     
     
     
     
    Show all issues

    Might be worth seeing how much work it'd be to remote-control something for this, but maybe not worth it.

    Though we should be testing auth failures. Don't we do that? I might be misunderstanding.

  6. 
      
david
maubin
  1. Ship It!
  2. 
      
chipx86
  1. 
      
  2. Show all issues

    Can we pick a different port? 1666 being the default port will conflict with actual local usage. How about something higher like 61666?

  3. 
      
david
maubin
  1. Ship It!
  2. 
      
chipx86
  1. Ship It!
  2. 
      
david
Review request changed
Status:
Completed
Change Summary:
Pushed to release-7.x (085da83)