def test_patch_unpatch(self): tracer = DummyTracer() # Test patch idempotence patch() patch() r = redis.Redis(port=REDIS_CONFIG["port"]) Pin.get_from(r).clone(tracer=tracer).onto(r) r.get("key") spans = tracer.pop() assert spans, spans assert len(spans) == 1 # Test unpatch unpatch() r = redis.Redis(port=REDIS_CONFIG["port"]) r.get("key") spans = tracer.pop() assert not spans, spans # Test patch again patch() r = redis.Redis(port=REDIS_CONFIG["port"]) Pin.get_from(r).clone(tracer=tracer).onto(r) r.get("key") spans = tracer.pop() assert spans, spans assert len(spans) == 1
def test_redis_legacy(): # ensure the old interface isn't broken, but doesn't trace tracer = DummyTracer() TracedRedisCache = get_traced_redis(tracer, "foo") r = TracedRedisCache(port=REDIS_CONFIG["port"]) r.set("a", "b") got = r.get("a") assert compat.to_unicode(got) == "b" assert not tracer.pop()