Skip to content

Commit

Permalink
B!! reset throttle count
Browse files Browse the repository at this point in the history
Co-Authored-By: Nitsan Avni <nitsanav@gmail.com>
Co-Authored-By: Susan Fung <38925660+susanfung@users.noreply.github.com>
Co-Authored-By: T. E. Green <78671457+Tegsy@users.noreply.github.com>
Co-Authored-By: Gregor Riegler <rieglerg85@gmail.com>
Co-Authored-By: Parth Das <19958690+daspeks@users.noreply.github.com>
Co-Authored-By: Tsvetan Tsvetanov <1549442+emdeha@users.noreply.github.com>
  • Loading branch information
7 people committed Dec 11, 2022
1 parent f8f5c6b commit 51a54a7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
5 changes: 4 additions & 1 deletion approvaltests/reporters/generic_diff_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,13 @@ def get_command(self, received: str, approved: str) -> List[str]:
def report(self, received_path: str, approved_path: str) -> bool:
if not self.is_working():
return False

GenericDiffReporter.hit_count += 1

if GenericDiffReporter.throttling_threshold < GenericDiffReporter.hit_count:
GenericDiffReporter.throttle_count += 1
print("Skipping the diff because the throttling threshold has been exceeded.")
return True
# do stuff

ensure_file_exists(approved_path)
command_array = self.get_command(received_path, approved_path)
Expand Down Expand Up @@ -92,3 +94,4 @@ def expand_program_files(path: str) -> str:
@staticmethod
def reset_hit_count():
GenericDiffReporter.hit_count = 0
GenericDiffReporter.throttle_count = 0
6 changes: 5 additions & 1 deletion mob-sessions-retros/2022-12-11 Throttling Diff Tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@

Goal: Throttle Diff Tools

Ideas:
## Ideas:
- Don't open additional diff tools if 5-8 are already open
- Should probably be done inside Generic Diff Reporter

## Todos for next Week:
- Improve the message shown when the reporter is throttling
- Test actual throttling
- How to option out to message
6 changes: 1 addition & 5 deletions tests/reporters/test_genericdiffreporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import re
import shutil
import unittest
from sre_constants import RANGE
from typing import cast

from approvaltests import Options
Expand Down Expand Up @@ -180,17 +179,14 @@ def assertFileIsEmpty(self, file_path: str) -> None:

def test_get_pycharm_reporter(self) -> None:
verify(str(self.factory.get("PyCharm")))

def test_diff_throttling(self) -> None:
# reset hit count
GenericDiffReporter.reset_hit_count()
# create reporter
reporter = self.instantiate_reporter_for_test()
# call 7 times
for i in range(0,7):
reporter.report("a.txt","b.txt")
assert 7 == GenericDiffReporter.hit_count
assert 2 == reporter.get_throttle_count()
# except 2 throttlings

def test_non_working_reporter_does_not_report(self) -> None:
self.assertFileDoesNotExist(self.approved_file_path)
Expand Down

0 comments on commit 51a54a7

Please sign in to comment.