Ejemplo n.º 1
0
def test_scoring_system(scoring_system):

    response = scoring_system.score(
        ScoreRequest("fakewiki", [1], ["fake"],
                     injection_caches={1: {
                         wait_time: 0.05
                     }},
                     model_info=['version']))
    # Print for debugging.
    print(response.errors)
    assert response.errors == {}
    assert response.scores == {1: {'fake': True}}
    assert response.model_info == {'fake': {'version': 'fake version'}}

    response = scoring_system.score(
        ScoreRequest("fakewiki", [1, 2], ["fake", "other_fake"],
                     injection_caches={
                         1: {
                             wait_time: 0.05
                         },
                         2: {
                             wait_time: 0.01
                         }
                     },
                     model_info=['version']))
    assert response.errors == {}
    assert response.scores == \
        {1: {'fake': True, 'other_fake': True},
         2: {'fake': True, 'other_fake': True}}
    assert response.model_info == \
        {'fake': {'version': 'fake version'},
         'other_fake': {'version': 'fake version'}}
Ejemplo n.º 2
0
def test_null():
    # Make sure we throw no errors.

    collector = Null()
    collector.precache_request(ScoreRequest("foo", [1], {"bar", "derp"}), 100)
    collector.scores_request(ScoreRequest("foo", list(range(50)), {"bar"}),
                             150)
    collector.datasources_extracted(ScoreRequest("foo", [1], {"bar"}), 10, 25)
    collector.score_processed(ScoreRequest("foo", [1], {"bar"}), 1.1)
    collector.score_timed_out(ScoreRequest("foo", [1], {"bar"}), 15.1)
    collector.score_cache_miss(ScoreRequest("foo", [1], {"derp"}), "derp")
    collector.score_cache_hit(ScoreRequest("foo", [1], {"bar"}), "bar")
    collector.score_errored(ScoreRequest("foo", [1], {"bar"}), "bar")
    collector.lock_acquired('pulpcounter', 3)
    collector.response_made(404, ScoreRequest("foo", [1], {"bar"}))
Ejemplo n.º 3
0
def test_single_thread():
    scoring_system = SingleThread({'fakewiki': fakewiki}, timeout=1.0)

    response = scoring_system.score(
        ScoreRequest("fakewiki", [1], ["fake"],
                     injection_caches={1: {
                         wait_time: 2.0
                     }}))
    assert 1 in response.errors, str(response.errors)
    assert isinstance(response.errors[1]['fake'], errors.TimeoutError), \
           type(response.errors[1]['fake'])
Ejemplo n.º 4
0
def test_timeout():
    scoring_system = ProcessPool({'fakewiki': fakewiki}, timeout=0.05)

    response = scoring_system.score(
        ScoreRequest("fakewiki", [1], ['fake'],
                     injection_caches={1: {
                         wait_time: 0.10
                     }}))
    assert 1 in response.errors, str(response.errors)
    assert isinstance(response.errors[1]['fake'], errors.TimeoutError), \
           type(response.errors[1]['fake'])
Ejemplo n.º 5
0
def test_rev_id_scorer():
    revid = RevIdScorer(version='0.0.1')
    fakewiki = ScoringContext('fakewiki', {'revid': revid}, OfflineExtractor())
    scoring_system = ProcessPool({'fakewiki': fakewiki},
                                 workers=8,
                                 score_cache=LRU(size=10))
    response = scoring_system.score(
        ScoreRequest("fakewiki", [1, 19], ["revid"], model_info=['']))
    print(response.scores, response.errors)
    assert response.model_info['revid']['version'] == '0.0.1'
    assert response.scores[1]['revid']['prediction'] is False
    assert response.scores[19]['revid']['prediction'] is True
Ejemplo n.º 6
0
def test_score_request():
    sr = ScoreResponse(FakeContext("foowiki"),
                       ScoreRequest("foo", [1, 2, 3], ["bar", "baz"]))

    sr.add_score(1, "bar", {"prediction": False})
    sr.add_score(1, "baz", {"prediction": True})
    sr.add_features(1, "baz", {"feature.rev_id": 1})
    sr.add_error(2, "bar", Exception("WTF"))
    sr.add_error(2, "baz", Exception("WTF"))
    sr.add_score(3, "bar", {"prediction": True})
    sr.add_score(3, "baz", {"prediction": False})
    sr.add_features(3, "baz", {"feature.rev_id": 3})

    assert sr.scores[3]['baz']['prediction'] is False
Ejemplo n.º 7
0
        def _process_score_map(request, model_names, rev_id, root_cache):
            logger.info("Generating a score map for {0}".format(
                request.format(rev_id, model_names)))

            if not isinstance(request, ScoreRequest):
                request = ScoreRequest.from_json(request)

            score_map = ScoringSystem._process_score_map(self,
                                                         request,
                                                         rev_id,
                                                         model_names,
                                                         root_cache=root_cache)
            logger.info("Completed generating score map for {0}".format(
                request.format(rev_id, model_names)))
            return score_map
Ejemplo n.º 8
0
def test_statsd():
    class StatsClient:

        def __init__(self):
            self.messages = []

        def incr(self, name, count=1):
            self.messages.append(("INCR", name, count))

        def timing(self, name, duration):
            self.messages.append(("TIMING", name, duration))

        @contextmanager
        def pipeline(self):
            yield self

    fake_client = StatsClient()

    collector = Statsd(fake_client)
    collector.precache_request(ScoreRequest("foo", [1], {"bar", "derp"}), 100)
    collector.scores_request(ScoreRequest("foo", list(range(50)), {"bar"}), 150)
    collector.datasources_extracted(ScoreRequest("foo", [1], {"bar"}), 10, 25)
    collector.score_processed(ScoreRequest("foo", [1], {"bar"}), 1.1)
    collector.score_timed_out(ScoreRequest("foo", [1], {"bar"}), 15.1)
    collector.score_cache_miss(ScoreRequest("foo", [1], {"derp"}), "derp")
    collector.score_cache_hit(ScoreRequest("foo", [1], {"bar"}), "bar")
    collector.score_errored(ScoreRequest("foo", [1], {"bar"}), "bar")
    collector.lock_acquired('pulpcounter', 3)
    collector.response_made(404, ScoreRequest("foo", [1], {"bar"}))

    assert set(fake_client.messages) - \
        {('TIMING', 'precache_request.foo.derp', 100000),
         ('TIMING', 'precache_request.foo.bar', 100000),
         ('TIMING', 'precache_request.foo', 100000),
         ('TIMING', 'precache_request', 100000),
         ('TIMING', 'scores_request.foo.bar.50', 150000),
         ('TIMING', 'scores_request.foo.bar', 150000),
         ('TIMING', 'scores_request.foo', 150000),
         ('TIMING', 'scores_request', 150000),
         ('INCR', 'revision_scored.foo.bar', 50),
         ('INCR', 'revision_scored.foo', 50),
         ('INCR', 'revision_scored', 50),
         ('TIMING', 'datasources_extracted.foo.bar.10', 25000),
         ('TIMING', 'datasources_extracted.foo.bar', 25000),
         ('TIMING', 'datasources_extracted.foo', 25000),
         ('TIMING', 'datasources_extracted', 25000),
         ('TIMING', 'score_processed.foo.bar', 1100.0),
         ('TIMING', 'score_processed.foo', 1100.0),
         ('TIMING', 'score_processed', 1100.0),
         ('TIMING', 'score_timed_out.foo.bar', 15100.0),
         ('TIMING', 'score_timed_out.foo', 15100.0),
         ('TIMING', 'score_timed_out', 15100.0),
         ('INCR', 'score_cache_miss.foo.derp', 1),
         ('INCR', 'score_cache_miss.foo', 1),
         ('INCR', 'score_cache_miss', 1),
         ('INCR', 'score_cache_hit.foo.bar', 1),
         ('INCR', 'score_cache_hit.foo', 1),
         ('INCR', 'score_cache_hit', 1),
         ('INCR', 'score_errored.foo.bar', 1),
         ('INCR', 'score_errored.foo', 1),
         ('TIMING', 'locking_response_time.pulpcounter', 3000),
         ('TIMING', 'locking_response_time', 3000),
         ('INCR', 'response.404', 1),
         ('INCR', 'response', 1),
         ('INCR', 'response.404.foo', 1),
         ('INCR', 'score_errored', 1)} == set()