tftpy icon indicating copy to clipboard operation
tftpy copied to clipboard

need methods for testing file locking

Open msoulier opened this issue 5 months ago • 4 comments

In issue #150 file locking was permanently on during an upload and we didn't notice. Simply having the transfer work is an insufficient test here. We need to be able to detect when options are not propagated to catch such problems, but the only methods I can think of are painfully manual.

msoulier avatar Jul 11 '25 13:07 msoulier

Suggestion: use a custom file-like class as the upload source.

ColBFritz avatar Jul 11 '25 15:07 ColBFritz

Is this intended to work on macos(darwin) ? I guess I assumed the target platform was unix/POSIX but the current flock implementation fails on macos:

  tests/test_tftpy.py::TestTftpyMisc::testStdin FAILED                     [ 97%]
  tests/test_tftpy.py::TestTftpyMisc::testStdout PASSED                    [100%]
  
  =================================== FAILURES ===================================
  ___________________________ TestTftpyMisc.testStdin ____________________________
  
  self = <test_tftpy.TestTftpyMisc testMethod=testStdin>
  
      def testStdin(self):
          cdir = os.path.dirname(os.path.abspath(__file__))
          script = os.path.join(cdir, "stdin.py")
          command = f"cat tests/640KBFILE | {script}"
          rv = subprocess.call(command, shell=True)
  >       self.assertTrue( rv == 0 )
  E       AssertionError: False is not true
  
  tests/test_tftpy.py:651: AssertionError
  ----------------------------- Captured stderr call -----------------------------
  Traceback (most recent call last):
    File "/Users/runner/work/tftpy/tftpy/tests/stdin.py", line 34, in <module>
      main()
    File "/Users/runner/work/tftpy/tftpy/tests/stdin.py", line 32, in main
      clientServerUploadOptions({}, filename="stdin_upload", input="-")
    File "/Users/runner/work/tftpy/tftpy/tests/stdin.py", line 23, in clientServerUploadOptions
      client.upload(filename, input)
    File "/Users/runner/work/tftpy/tftpy/tftpy/TftpClient.py", line 136, in upload
      c.start()
    File "/Users/runner/work/tftpy/tftpy/tftpy/TftpContexts.py", line 140, in __exit__
      self.end()
    File "/Users/runner/work/tftpy/tftpy/tftpy/TftpContexts.py", line 390, in end
      super().end()
    File "/Users/runner/work/tftpy/tftpy/tftpy/TftpContexts.py", line 168, in end
      lockfile(self.fileobj, unlock=True)
    File "/Users/runner/work/tftpy/tftpy/tftpy/TftpShared.py", line 45, in lockfile
      fcntl.flock(fobj, mode)
  OSError: [Errno 45] Operation not supported

sarnold avatar Jul 12 '25 04:07 sarnold

That surprises me. I thought that BSD would support flock. I'll have to borrow an OSX box to troubleshoot this on.

msoulier avatar Jul 12 '25 11:07 msoulier

All my hardware runs Linux so I can only test things on macos/windows in Github CI. Also my main example consumer project is full of POSIX daemons that won't run on windows, but has a console "server" and example tox workflow that uses curl for the test client; there might be some interesting examples there: https://github.com/sarnold/pyserv

sarnold avatar Jul 12 '25 17:07 sarnold