<commit_before># -*- coding: utf-8 -
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#
# Copyright 2011 Cloudant, Inc.

import t
import bucky.statsd

@t.set_cfg("statsd_flush_time", 0.5)
@t.udp_srv(bucky.statsd.StatsDServer)
def test_simple_counter(q, s):
    s.send("gorm:1|c")
    t.same_stat("stats.gorm", 2, q.get())
    t.same_stat("stats.numStats", 1, q.get())


@t.set_cfg("statsd_flush_time", 0.5)
@t.udp_srv(bucky.statsd.StatsDServer)
def test_multiple_messages(q, s):
    s.send("gorm:1|c")
    s.send("gorm:1|c")
    t.same_stat("stats.gorm", 4, q.get())
    t.same_stat("stats.numStats", 1, q.get())


@t.set_cfg("statsd_flush_time", 0.5)
@t.udp_srv(bucky.statsd.StatsDServer)
def test_larger_count(q, s):
    s.send("gorm:5|c")
    t.same_stat("stats.gorm", 10, q.get())
    t.same_stat("stats.numStats", 1, q.get())


@t.set_cfg("statsd_flush_time", 0.5)
@t.udp_srv(bucky.statsd.StatsDServer)
def test_multiple_counters(q, s):
    s.send("gorm:1|c")
    s.send("gurm:1|c")
    stats = {"stats.gorm": 2, "stats.gurm": 2}
    for i in range(2):
        stat = q.get()
        t.isin(stat[0], stats)
        t.eq(stats[stat[0]], stat[1])
        t.gt(stat[1], 0)
        stats.pop(stat[0])
    t.same_stat("stats.numStats", 2, q.get())


@t.set_cfg("statsd_flush_time", 0.5)
@t.udp_srv(bucky.statsd.StatsDServer)
def test_simple_timer(q, s):
    for i in range(9):
        s.send("gorm:1|ms")
    s.send("gorm:2|ms")
    t.same_stat("stats.timers.gorm.mean", 1, q.get())
    t.same_stat("stats.timers.gorm.upper", 2, q.get())
    t.same_stat("stats.timers.gorm.upper_90", 1, q.get())
    t.same_stat("stats.timers.gorm.lower", 1, q.get())
    t.same_stat("stats.timers.gorm.count", 9, q.get())
    t.same_stat("stats.numStats", 1, q.get())
<commit_msg>Fix the statsd tests<commit_after># -*- coding: utf-8 -
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#
# Copyright 2011 Cloudant, Inc.

import t
import bucky.statsd

@t.set_cfg("statsd_flush_time", 0.5)
@t.udp_srv(bucky.statsd.StatsDServer)
def test_simple_counter(q, s):
    s.send("gorm:1|c")
    t.same_stat("stats.gorm", 2, q.get())
    t.same_stat("stats_counts.gorm", 1, q.get())
    t.same_stat("stats.numStats", 1, q.get())


@t.set_cfg("statsd_flush_time", 0.5)
@t.udp_srv(bucky.statsd.StatsDServer)
def test_multiple_messages(q, s):
    s.send("gorm:1|c")
    s.send("gorm:1|c")
    t.same_stat("stats.gorm", 4, q.get())
    t.same_stat("stats_counts.gorm", 2, q.get())
    t.same_stat("stats.numStats", 1, q.get())


@t.set_cfg("statsd_flush_time", 0.5)
@t.udp_srv(bucky.statsd.StatsDServer)
def test_larger_count(q, s):
    s.send("gorm:5|c")
    t.same_stat("stats.gorm", 10, q.get())
    t.same_stat("stats_counts.gorm", 5, q.get())
    t.same_stat("stats.numStats", 1, q.get())


@t.set_cfg("statsd_flush_time", 0.5)
@t.udp_srv(bucky.statsd.StatsDServer)
def test_multiple_counters(q, s):
    s.send("gorm:1|c")
    s.send("gurm:1|c")
    stats = {
        "stats.gorm": 2,
        "stats_counts.gorm": 1,
        "stats.gurm": 2,
        "stats_counts.gurm": 1
    }
    for i in range(4):
        stat = q.get()
        t.isin(stat[0], stats)
        t.eq(stats[stat[0]], stat[1])
        t.gt(stat[1], 0)
        stats.pop(stat[0])
    t.same_stat("stats.numStats", 2, q.get())


@t.set_cfg("statsd_flush_time", 0.5)
@t.udp_srv(bucky.statsd.StatsDServer)
def test_simple_timer(q, s):
    for i in range(9):
        s.send("gorm:1|ms")
    s.send("gorm:2|ms")
    t.same_stat("stats.timers.gorm.mean", 1, q.get())
    t.same_stat("stats.timers.gorm.upper", 2, q.get())
    t.same_stat("stats.timers.gorm.upper_90", 1, q.get())
    t.same_stat("stats.timers.gorm.lower", 1, q.get())
    t.same_stat("stats.timers.gorm.count", 10, q.get())
    t.same_stat("stats.numStats", 1, q.get())

{'fraction_non_alphanumeric': 0.1767177978566926, 'fraction_numerical': 0.02353435595713385, 'mean_word_length': 3.7222222222222223, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5737423', 'n_tokens_mistral': 1988, 'n_tokens_neox': 1920, 'n_words': 392}