Skip to content

Conversation

@ptpt
Copy link
Member

@ptpt ptpt commented Aug 27, 2025

  • fix: race condition in image uploader and add tests
  • Add tests for ImageSequenceUploader. Follow the following principles:
  • I saw that you use multithreads in test_image_sequence_uploader_multithreading_with_cache_enabled. No need to do that because sequence_uploader.upload_images is using inside multithreading. We can guranteee that sequence_uploader.upload_images won't be called in multithreads
  • Using cached_time to determine if it's cached is probably not reliable. Try mock some internal implementation, e.g. if single_image_uploader.cache.get() is called and filehandle if filehandle is cached there
  • increase num_images
  • Ok, it looks like it is hard to tests with the current implementation. Let's make some changes in uploader.py
  • Ok now let's improve tests. As we exposed both ImageSequenceUploader.cache and SingleImageUploader.cache, which means you can update them after construction, and run assertions based on the cache instance
  • I don't see you are calling sequence_uploader.upload_images in test_image_sequence_uploader_cache_hits_second_run
  • simplify tests
  • enable upload_cache_path
  • refactor
  • update tests
  • rename
  • tests

ptpt added 14 commits August 27, 2025 09:58
- Test that it works in multithreads environement with caches enabled
- Test that it works in multithreads with cache disabled
- when cache is enabled, test that cache hits for the second run
- Do not use mock unless badly needed (See TestSingleImageUploader as exmple)
- Do not import modules inside the test class (always add imports to the top of test file)
…threading_with_cache_enabled. No need to do that because `sequence_uploader.upload_images` is using inside multithreading. We can guranteee that sequence_uploader.upload_images won't be called in multithreads
…e. Try mock some internal implementation, e.g. if single_image_uploader.cache.get() is called and filehandle if filehandle is cached there
…. Let's make some changes in uploader.py

1. Make SingleImageUploader fully thread-safe, which means move _maybe_create_persistent_cache_instance to ImageSequenceUploader perhaps
2. Create the cache instance in ImageSequenceUploader and pass in the  instance to SingleImageUploader to create the single image uploader instance
3. Use single image uploader instance for all uploads in ImageSequenceUploader

Make change in implementation only for now (i.e. do not change tests).
…cache and SingleImageUploader.cache, which means you can update them after construction, and run assertions based on the cache instance
…_image_sequence_uploader_cache_hits_second_run

Make sure test these scenario in that test:

1. make sure cache is enabled
2. for the first upload_images(a, b, c), make sure no caches are hit
3. fir the second upload_images(c, d, e), make sure c is using the cached value, d and e are not cached
4. eventually a, b, c, d, e are all cached
@meta-cla meta-cla bot added the cla signed label Aug 27, 2025
@ptpt ptpt merged commit a4d27b9 into main Aug 27, 2025
16 checks passed
@ptpt ptpt deleted the fix-race-condition-image-uploader branch August 27, 2025 23:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants