def test_shouldRunNoMoreThanProvidedTimesPerSecond(self): calls = 20 per_second = 10 limited = limit(per_second=per_second) for i in range(0, calls + 1): limited(self.marker_function)() first = self.timestamps[0] last = self.timestamps[-1] self.assertTrue(last - first > calls / per_second, "Should run all %s calls to function for time greater" " than %s seconds." % (calls, calls / per_second))
def test_shouldRunNoMoreThanProvidedTimesPerMinute(self): calls = 20 per_minute = 10 limited = limit(per_minute=per_minute) for i in range(0, calls + 1): limited(self.marker_function)() first = self.timestamps[0] last = self.timestamps[-1] self.assertTrue((last - first) > 60.0 * calls / per_minute, "Should run all %s calls to function for time greater" "than %s minutes." % (calls, 60.0 * calls / per_minute))
def test_shouldRunNoMoreThanProvidedTimesPerMinute(self): calls = 20 per_minute = 10 limited = limit(per_minute=per_minute) for i in range(0, calls + 1): limited(self.marker_function)() first = self.timestamps[0] last = self.timestamps[-1] self.assertTrue( (last - first) > 60.0 * calls / per_minute, "Should run all %s calls to function for time greater" "than %s minutes." % (calls, 60.0 * calls / per_minute))
def test_shouldRunNoMoreThanProvidedTimesPerSecond(self): calls = 20 per_second = 10 limited = limit(per_second=per_second) for i in range(0, calls + 1): limited(self.marker_function)() first = self.timestamps[0] last = self.timestamps[-1] self.assertTrue( last - first > calls / per_second, "Should run all %s calls to function for time greater" " than %s seconds." % (calls, calls / per_second))
async def update_feeds(self, force=False, resume=False, replace=False): logger.info(f"update_feeds: {force} {resume} {replace}") with db_session: # feeds = select(f for f in self.FEED_CLASS if f in self.selected_channels) # if not self.feed_entity: # feeds = self.FEED_CLASS.select() # else: # feeds = [self.feed_entity] for feed in self.selected_channels: if (force or feed.updated is None or datetime.now() - feed.updated > timedelta(seconds=feed.update_interval)): logger.info(f"updating {feed.locator}") with limit(self.limiter): await feed.update(resume=resume, replace=replace)
def test_shouldFailWhenNoLimitsProvided(self): with self.assertRaises(limit.Exception): limit()