Test for concurrent builds
@@ -8,11 +8,12 @@ from django.test import TestCase
from django_dynamic_fixture import get
from unittest.mock import call
-from readthedocs.builds.constants import LATEST
-from readthedocs.builds.models import Version
-from readthedocs.core.utils import slugify, trigger_build
+from readthedocs.builds.constants import LATEST, BUILD_STATE_BUILDING
+from readthedocs.builds.models import Version, Build
+from readthedocs.core.utils import slugify, trigger_build, prepare_build
from readthedocs.core.utils.general import wipe_version_via_slugs
-from readthedocs.projects.models import Project
+from readthedocs.doc_builder.exceptions import BuildMaxConcurrencyError
+from readthedocs.projects.models import Project, Feature
from readthedocs.projects.tasks import remove_dirs
@@ -176,6 +177,47 @@ class CoreUtilTests(TestCase):
immutable=True,
)
+ @mock.patch('readthedocs.projects.tasks.update_docs_task')
+ def test_trigger_max_concurrency_reached(self, update_docs):
+ get(
+ Feature,
+ feature_id=Feature.LIMIT_CONCURRENT_BUILDS,
+ projects=[self.project],
+ )
+ max_concurrent_builds = 2
+ for _ in range(max_concurrent_builds):
+ get(
+ Build,
+ state=BUILD_STATE_BUILDING,
+ project=self.project,
+ version=self.version,
+ )
+ self.project.max_concurrent_builds = max_concurrent_builds
+ self.project.save()
+
+ trigger_build(project=self.project, version=self.version)
+ kwargs = {
+ 'record': True,
+ 'force': False,
+ 'build_pk': mock.ANY,
+ 'commit': None
+ }
+ options = {
+ 'queue': mock.ANY,
+ 'time_limit': 720,
+ 'soft_time_limit': 600,
+ 'countdown': 5 * 60,
+ 'max_retries': 25,
+ }
+ update_docs.signature.assert_called_with(
+ args=(self.version.pk,),
+ kwargs=kwargs,
+ options=options,
+ immutable=True,
+ )
+ build = self.project.builds.first()
+ self.assertEqual(build.error, BuildMaxConcurrencyError.message.format(limit=max_concurrent_builds))
+
def test_slugify(self):
"""Test additional slugify."""
self.assertEqual(
