Commit a4d27b9
authored
fix: race condition in image uploader (#779)
* fix: race condition in image uploader and add tests
* Add tests for ImageSequenceUploader. Follow the following principles:
- 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)
* 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
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).
* 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
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
* simplify tests
* enable upload_cache_path
* refactor
* update tests
* rename
* tests
* Assert that results from the uploader.upload_images() in TestImageSequenceUploader has not errors
* cache path1 parent e03d5f5 commit a4d27b9
3 files changed
Lines changed: 588 additions & 62 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
162 | 162 | | |
163 | 163 | | |
164 | 164 | | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
165 | 170 | | |
166 | 171 | | |
167 | 172 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
56 | 57 | | |
57 | 58 | | |
58 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
59 | 63 | | |
60 | 64 | | |
61 | 65 | | |
| |||
471 | 475 | | |
472 | 476 | | |
473 | 477 | | |
474 | | - | |
| 478 | + | |
475 | 479 | | |
476 | 480 | | |
477 | 481 | | |
| |||
537 | 541 | | |
538 | 542 | | |
539 | 543 | | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
540 | 551 | | |
541 | 552 | | |
542 | 553 | | |
| |||
688 | 699 | | |
689 | 700 | | |
690 | 701 | | |
691 | | - | |
692 | | - | |
693 | | - | |
694 | | - | |
695 | 702 | | |
696 | 703 | | |
697 | 704 | | |
| |||
710 | 717 | | |
711 | 718 | | |
712 | 719 | | |
713 | | - | |
714 | | - | |
| 720 | + | |
| 721 | + | |
715 | 722 | | |
716 | 723 | | |
717 | 724 | | |
| |||
731 | 738 | | |
732 | 739 | | |
733 | 740 | | |
734 | | - | |
| 741 | + | |
735 | 742 | | |
736 | 743 | | |
737 | 744 | | |
738 | | - | |
| 745 | + | |
739 | 746 | | |
740 | 747 | | |
741 | | - | |
742 | | - | |
743 | | - | |
744 | | - | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
745 | 751 | | |
| 752 | + | |
746 | 753 | | |
747 | | - | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
748 | 758 | | |
749 | 759 | | |
750 | 760 | | |
751 | | - | |
| 761 | + | |
752 | 762 | | |
753 | 763 | | |
754 | 764 | | |
| |||
786 | 796 | | |
787 | 797 | | |
788 | 798 | | |
789 | | - | |
790 | | - | |
791 | | - | |
792 | | - | |
793 | | - | |
794 | | - | |
795 | | - | |
796 | | - | |
797 | | - | |
798 | | - | |
799 | | - | |
800 | | - | |
801 | | - | |
802 | | - | |
803 | | - | |
804 | | - | |
805 | | - | |
806 | | - | |
807 | | - | |
808 | | - | |
809 | | - | |
810 | | - | |
811 | | - | |
812 | | - | |
813 | | - | |
814 | | - | |
815 | | - | |
816 | | - | |
817 | | - | |
818 | | - | |
819 | | - | |
820 | | - | |
821 | | - | |
822 | | - | |
823 | | - | |
824 | | - | |
825 | | - | |
826 | | - | |
827 | | - | |
828 | | - | |
829 | | - | |
830 | | - | |
831 | | - | |
832 | | - | |
833 | | - | |
| 799 | + | |
834 | 800 | | |
835 | 801 | | |
836 | 802 | | |
| |||
840 | 806 | | |
841 | 807 | | |
842 | 808 | | |
| 809 | + | |
843 | 810 | | |
844 | 811 | | |
845 | 812 | | |
| |||
1168 | 1135 | | |
1169 | 1136 | | |
1170 | 1137 | | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
| 1190 | + | |
| 1191 | + | |
0 commit comments