Closed alexandrevicenzi closed 5 years ago
Code looks good, but I think tests should be improved. What we should test here is that if you create two threads then pulp client in thread1 shoulnd't be identical to pulp client in thread 2
Pulp client will be the same in both thread, this is the design on ubipop, that's why the session was shared. The only thing that should not be shared is the session.
Pulp client will be the same in both thread, this is the design on ubipop, that's why the session was shared. The only thing that should not be shared is the session.
Ok, sorry I chose wrong word. I meant session, not pulp client. So Basically, you can see it like this:
import threading
import random
class Client1(object):
def __init__(self):
self.local = threading.local()
def make_session(self):
if not hasattr(self.local, "session"):
self.local.session = random.randrange(1000)
def session(self):
return self.local.session
def do_client_thing(c):
c.make_session()
print id(c.session())
c = Client1()
ts = [threading.Thread(target=do_client_thing, args=(c,)) for _ in range(5)]
[t.start() for t in ts]
[t.join() for t in ts]
And then to test it, it should return 5 different object ids. That's how you can test session isn't shared.
With this the session won't be shared across multiple threads.
This fix #57.