Skip to content

tests: get connect_nonblock_xfer.py test working again and simplify it #16156

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

Merged
merged 2 commits into from
Nov 13, 2024

Conversation

dpgeorge
Copy link
Member

@dpgeorge dpgeorge commented Nov 5, 2024

Summary

CPython changed its non-blocking socket behaviour recently and this test would not run under CPython anymore. So the following steps were taken to get the test working again and then simplify it:

  • Run the test against CPython 3.10.10 and capture the output into the .exp file for the test.
  • Run this test on unix port of MicroPython and verify that the output matches the CPython 3.10.10 output in the new .exp file (it did). From now on take unix MicroPython as the source of truth for this test when modifying it.
  • Remove all code that was there for CPython compatibility.
  • Make it print out more useful information during the test run, including names of the OSError errno values.
  • Add polling of the socket before the send/write/recv/read to verify that the poll gives the correct result in non-blocking mode.

As part of this, it was found that bare-metal lwIP boards (eg PYBD_SF2, RPI_PICO_W) failed the test due to non-conforming behaviour of send/write on a non-blocking socket that's not yet connected. That issue is also fixed in this PR.

Testing

Tested on unix MicroPython, ESP32_GENERIC, PYBD_SF2 and RPI_PICO_W boards. This test and all existing network tests pass. Multinet tests pass.

Trade-offs and Alternatives

Matching CPython behaviour here would be a lot of work and changes to socket code, which now uses BlockingIOError. I don't think we need to do that, not a good use of time, is a big churn of functionality,
and many things need to be retested and fixed (eg asyncio).

esp8266 can't pass this test because axtls doesn't fully support non-blocking mode, so the test is skipped on this platform. It does actually pass the normal socket (not TLS) bits of this test, but separating those out into a separate test is not worth it, IMO.

@dpgeorge dpgeorge added the tests Relates to tests/ directory in source label Nov 5, 2024
Copy link

codecov bot commented Nov 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.57%. Comparing base (3844733) to head (6902362).
Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #16156   +/-   ##
=======================================
  Coverage   98.57%   98.57%           
=======================================
  Files         164      164           
  Lines       21345    21345           
=======================================
  Hits        21041    21041           
  Misses        304      304           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dpgeorge dpgeorge force-pushed the tests-fix-connect-nonblock-xfer branch from 4745d57 to aeae52f Compare November 5, 2024 01:11
Copy link

github-actions bot commented Nov 5, 2024

Code size report:

   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
     mimxrt:    +0 +0.000% TEENSY40
        rp2:    +8 +0.001% RPI_PICO_W
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +0 +0.000% VIRT_RV32

@dpgeorge dpgeorge requested a review from projectgus November 11, 2024 01:25
Copy link
Contributor

@projectgus projectgus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with the rationale about not tracking CPython here.

This follows the behaviour of unix MicroPython (POSIX sockets) and the
esp32 port.

Signed-off-by: Damien George <damien@micropython.org>
CPython changed its non-blocking socket behaviour recently and this test
would not run under CPython anymore.  So the following steps were taken to
get the test working again and then simplify it:

- Run the test against CPython 3.10.10 and capture the output into the .exp
  file for the test.

- Run this test on unix port of MicroPython and verify that the output
  matches the CPython 3.10.10 output in the new .exp file (it did).  From
  now on take unix MicroPython as the source of truth for this test when
  modifying it.

- Remove all code that was there for CPython compatibility.

- Make it print out more useful information during the test run, including
  names of the OSError errno values.

- Add polling of the socket before the send/write/recv/read to verify that
  the poll gives the correct result in non-blocking mode.

Tested on unix MicroPython, ESP32_GENERIC, PYBD_SF2 and RPI_PICO_W boards.

Signed-off-by: Damien George <damien@micropython.org>
@dpgeorge dpgeorge force-pushed the tests-fix-connect-nonblock-xfer branch from aeae52f to 6902362 Compare November 13, 2024 00:45
@dpgeorge dpgeorge merged commit 6902362 into micropython:master Nov 13, 2024
59 of 61 checks passed
@dpgeorge dpgeorge deleted the tests-fix-connect-nonblock-xfer branch November 13, 2024 00:47
@dpgeorge
Copy link
Member Author

esp8266 can't pass this test because axtls doesn't fully support non-blocking mode, so the test is skipped on this platform. It does actually pass the normal socket (not TLS) bits of this test, but separating those out into a separate test is not worth it, IMO.

Converting this test to use unittest in #16216 allows it to run on esp8266 (skipping the TLS bits).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Relates to tests/ directory in source
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants