#1674 test_build: mock rpmbuild -bs
Opened 3 years ago by otaylor. Modified a year ago
otaylor/fm-orchestrator mock-rpmbuild-bs  into  master

@@ -499,8 +499,14 @@ 

          )

          self.patch_config_broker.start()

  

+         self.patch_execute_cmd = patch(

+             "module_build_service.builder.KojiModuleBuilder.execute_cmd",

+             side_effect=self.execute_cmd)

+         self.patch_execute_cmd.start()

+ 

      def teardown_method(self, test_method):

          self.patch_config_broker.stop()

+         self.patch_execute_cmd.stop()

          FakeModuleBuilder.reset()

          cleanup_moksha()

          for i in range(20):
@@ -509,6 +515,30 @@ 

              except Exception:

                  pass

  

+     def execute_cmd(self, args, **kwargs):

+         pattern = [

+             r"rpmbuild$",

+             r"-bs$",

+             r"(.*).spec$",

+             r"--define$",

+             r"_topdir (.*)$",

+             r"--define$",

+             r"_sourcedir (.*)$",

+         ]

+         assert len(args) == len(pattern)

+         matches = [re.match(pattern[i], arg) for i, arg in enumerate(args)]

+         assert all(matches)

+ 

+         name = matches[2].group(1)

+         topdir = matches[4].group(1)

+         srpmdir = os.path.join(topdir, "SRPMS")

+         if not os.path.exists(srpmdir):

+             os.makedirs(srpmdir)

+         with open(os.path.join(srpmdir, name + "-1-1.src.rpm"), "w"):

+             pass

+ 

+         return ("", "")

+ 

      @pytest.mark.parametrize("mmd_version", [1, 2])

      @patch("module_build_service.web.auth.get_user", return_value=user)

      @patch("module_build_service.common.scm.SCM")

On my system this improves the time to run test_build.py from 26 seconds
to 10 seconds - and the overall test run from about 56 seconds to 40
seconds - a 29% improvement.

When I repeat the testing, the impact of mocking rpmbuild -bs seeems to be minimal (makes test_build.py 0.7 seconds faster), and almost all of the slowness in test_build.py comes from another source:

In: moksha/moksha.hub/moksha/hub/zeromq/zeromq.py

        # This is required so that the publishing socket can fully set itself
        # up before we start trying to send messages on it.  This is a
        # documented zmq issue that they do not plan to fix.
        time.sleep(1)

Without patching that out, the run for test_build.py is still around 30 seconds. Not sure what was going on with my testing earlier.

I may try to come up with a patch for that. For now this PR can probably be ignored (it's not wrong, it just doesn't produce the advertised gains.)

rebased onto c20aa7e

2 years ago

rebased onto 86d01cb

a year ago

rebased onto 3ec0f27

a year ago
Metadata