@@ -642,6 +642,116 @@ def test_remove_module_cache_with_namespace_remain(self):
642
642
DependencyManager ._remove_module_cache (self ._customer_deps_path )
643
643
self .assertIsNotNone (common_module )
644
644
645
+ @unittest .skipIf (sys .version_info .minor > 7 ,
646
+ "The worker brings different protobuf versions"
647
+ "between 3.7 and 3.8+." )
648
+ def test_newrelic_protobuf_import_scenario_worker_deps_37 (self ):
649
+ # https://github.com/Azure/azure-functions-python-worker/issues/1339
650
+ # newrelic checks if protobuf has been imported and based on the
651
+ # version it finds, imports a specific pb2 file.
652
+
653
+ # PIWD = 0. protobuf is brought through the worker's deps.
654
+ os .environ ['PYTHON_ISOLATE_WORKER_DEPENDENCIES' ] = 'false'
655
+
656
+ # Setup paths
657
+ DependencyManager .worker_deps_path = self ._worker_deps_path
658
+ DependencyManager .cx_deps_path = self ._customer_deps_path
659
+ DependencyManager .cx_working_dir = self ._customer_func_path
660
+
661
+ DependencyManager .prioritize_customer_dependencies ()
662
+
663
+ # protobuf v3 is found
664
+ from google .protobuf import __version__
665
+
666
+ protobuf_version = tuple (int (v ) for v in __version__ .split ("." ))
667
+ self .assertIsNotNone (protobuf_version )
668
+ self .assertEqual (protobuf_version [0 ], 3 )
669
+
670
+ @unittest .skipIf (sys .version_info .minor <= 7 ,
671
+ "The worker brings different protobuf versions"
672
+ "between 3.7 and 3.8+." )
673
+ def test_newrelic_protobuf_import_scenario_worker_deps (self ):
674
+ # https://github.com/Azure/azure-functions-python-worker/issues/1339
675
+ # newrelic checks if protobuf has been imported and based on the
676
+ # version it finds, imports a specific pb2 file.
677
+
678
+ # PIWD = 0. protobuf is brought through the worker's deps.
679
+ os .environ ['PYTHON_ISOLATE_WORKER_DEPENDENCIES' ] = 'false'
680
+
681
+ # Setup paths
682
+ DependencyManager .worker_deps_path = self ._worker_deps_path
683
+ DependencyManager .cx_deps_path = self ._customer_deps_path
684
+ DependencyManager .cx_working_dir = self ._customer_func_path
685
+
686
+ DependencyManager .prioritize_customer_dependencies ()
687
+
688
+ # protobuf v4 is found
689
+ from google .protobuf import __version__
690
+
691
+ protobuf_version = tuple (int (v ) for v in __version__ .split ("." ))
692
+ self .assertIsNotNone (protobuf_version )
693
+ self .assertEqual (protobuf_version [0 ], 4 )
694
+
695
+ @unittest .skipIf (sys .version_info .minor > 7 ,
696
+ "The worker brings different protobuf versions"
697
+ "between 3.7 and 3.8+." )
698
+ def test_newrelic_protobuf_import_scenario_user_deps_37 (self ):
699
+ # https://github.com/Azure/azure-functions-python-worker/issues/1339
700
+ # newrelic checks if protobuf has been imported and based on the
701
+ # version it finds, imports a specific pb2 file.
702
+
703
+ # PIWD = 1. protobuf is brought through the user's deps.
704
+ os .environ ['PYTHON_ISOLATE_WORKER_DEPENDENCIES' ] = 'true'
705
+
706
+ # Setup paths
707
+ DependencyManager .worker_deps_path = self ._worker_deps_path
708
+ DependencyManager .cx_deps_path = self ._customer_deps_path
709
+ DependencyManager .cx_working_dir = self ._customer_func_path
710
+
711
+ DependencyManager .prioritize_customer_dependencies ()
712
+
713
+ # protobuf is found from worker deps, but newrelic won't find it
714
+ from google .protobuf import __version__
715
+
716
+ protobuf_version = tuple (int (v ) for v in __version__ .split ("." ))
717
+ self .assertIsNotNone (protobuf_version )
718
+
719
+ # newrelic tries to import protobuf v3
720
+ self .assertEqual (protobuf_version [0 ], 3 )
721
+
722
+ # newrelic tries to import protobuf v4
723
+ self .assertNotEqual (protobuf_version [0 ], 4 )
724
+
725
+ @unittest .skipIf (sys .version_info .minor <= 7 ,
726
+ "The worker brings different protobuf versions"
727
+ "between 3.7 and 3.8+." )
728
+ def test_newrelic_protobuf_import_scenario_user_deps (self ):
729
+ # https://github.com/Azure/azure-functions-python-worker/issues/1339
730
+ # newrelic checks if protobuf has been imported and based on the
731
+ # version it finds, imports a specific pb2 file.
732
+
733
+ # PIWD = 1. protobuf is brought through the user's deps.
734
+ os .environ ['PYTHON_ISOLATE_WORKER_DEPENDENCIES' ] = 'true'
735
+
736
+ # Setup paths
737
+ DependencyManager .worker_deps_path = self ._worker_deps_path
738
+ DependencyManager .cx_deps_path = self ._customer_deps_path
739
+ DependencyManager .cx_working_dir = self ._customer_func_path
740
+
741
+ DependencyManager .prioritize_customer_dependencies ()
742
+
743
+ # protobuf is found from worker deps, but newrelic won't find it
744
+ from google .protobuf import __version__
745
+
746
+ protobuf_version = tuple (int (v ) for v in __version__ .split ("." ))
747
+ self .assertIsNotNone (protobuf_version )
748
+
749
+ # newrelic tries to import protobuf v4
750
+ self .assertEqual (protobuf_version [0 ], 4 )
751
+
752
+ # newrelic tries to import protobuf v3
753
+ self .assertNotEqual (protobuf_version [0 ], 3 )
754
+
645
755
def _initialize_scenario (self ):
646
756
# Setup app settings
647
757
os .environ ['PYTHON_ISOLATE_WORKER_DEPENDENCIES' ] = 'true'
0 commit comments