-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c29e352
commit 64fb95f
Showing
4 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Standard Library | ||
import types | ||
|
||
# First Party | ||
from smdebug.core.config_constants import LOG_DUPLICATION_THRESHOLD | ||
from smdebug.core.logger import DuplicateLogFilter | ||
from smdebug.core.utils import get_logger | ||
|
||
|
||
def test_dup_filter(): | ||
logger = get_logger() | ||
dup_filter = None | ||
|
||
for _filter in logger.filters: | ||
if isinstance(_filter, DuplicateLogFilter): | ||
dup_filter = _filter | ||
dup_filter.test_counter = 0 | ||
|
||
dup_filter.old_filter = dup_filter.filter | ||
|
||
def filter(self, record): | ||
if self.old_filter(record): | ||
self.test_counter += 1 | ||
return True | ||
else: | ||
return False | ||
|
||
dup_filter.filter = types.MethodType(filter, dup_filter) | ||
|
||
for _ in range(10): | ||
logger.warning("I love spam musubi") | ||
|
||
assert dup_filter.test_counter == LOG_DUPLICATION_THRESHOLD |