5
5
6
6
import urllib3
7
7
import unittest
8
+ import pytest
9
+ import sys
8
10
import requests
9
11
12
+ from multiprocessing .pool import ThreadPool
13
+ from time import sleep
14
+
10
15
import tests .apps .flask_app
11
16
from ..helpers import testenv
12
17
from instana .singletons import agent , tracer
@@ -30,6 +35,43 @@ def test_vanilla_requests(self):
30
35
spans = self .recorder .queued_spans ()
31
36
self .assertEqual (1 , len (spans ))
32
37
38
+ @pytest .mark .skipif (sys .version_info [0 ] < 3 , reason = "ThreadPool works differently on python 2" )
39
+ def test_parallel_requests (self ):
40
+ http_pool_5 = urllib3 .PoolManager (num_pools = 5 )
41
+
42
+ def task (num ):
43
+ r = http_pool_5 .request ('GET' , testenv ["wsgi_server" ] + '/' , fields = {'num' : num })
44
+ return r
45
+
46
+ with ThreadPool (processes = 5 ) as executor :
47
+ # iterate over results as they become available
48
+ for result in executor .map (task , (1 , 2 , 3 , 4 , 5 )):
49
+ self .assertEqual (result .status , 200 )
50
+
51
+ spans = self .recorder .queued_spans ()
52
+ self .assertEqual (5 , len (spans ))
53
+ nums = map (lambda s : s .data ['http' ]['params' ].split ('=' )[1 ], spans )
54
+ self .assertEqual (set (nums ), set (('1' , '2' , '3' , '4' , '5' )))
55
+
56
+ def test_customers_setup_zd_26466 (self ):
57
+ def make_request (u = None ):
58
+ sleep (10 )
59
+ x = requests .get (testenv ["wsgi_server" ] + '/' )
60
+ sleep (10 )
61
+ return x .status_code
62
+
63
+ status = make_request ()
64
+ #print(f'request made outside threadpool, instana should instrument - status: {status}')
65
+
66
+ threadpool_size = 15
67
+ pool = ThreadPool (processes = threadpool_size )
68
+ res = pool .map (make_request , [u for u in range (threadpool_size )])
69
+ #print(f'requests made within threadpool, instana does not instrument - statuses: {res}')
70
+
71
+ spans = self .recorder .queued_spans ()
72
+ self .assertEqual (16 , len (spans ))
73
+
74
+
33
75
def test_get_request (self ):
34
76
with tracer .start_active_span ('test' ):
35
77
r = self .http .request ('GET' , testenv ["wsgi_server" ] + '/' )
0 commit comments