Esempio n. 1
0
    def testDo_NotBlessedIfErrorContinues(self):
        # Run executor.
        infra_validator = executor.Executor(self._context)
        with mock.patch.object(infra_validator,
                               '_ValidateOnce') as validate_mock:
            # 3 Errors are not tolerable.
            validate_mock.side_effect = [
                ValueError, ValueError, ValueError, None
            ]
            infra_validator.Do(self._input_dict, self._output_dict,
                               self._exec_properties)

        # Check not blessed.
        self.assertNotBlessed()
Esempio n. 2
0
 def testValidateOnce_LoadOnly_FailIfRunnerWaitRaises(self):
   infra_validator = executor.Executor(self._context)
   with mock.patch.object(self._serving_binary, 'MakeClient'):
     with mock.patch.object(
         executor, '_create_model_server_runner') as mock_runner_factory:
       mock_runner = mock_runner_factory.return_value
       mock_runner.WaitUntilRunning.side_effect = ValueError
       with self.assertRaises(ValueError):
         infra_validator._ValidateOnce(
             model_path=self._model_path,
             serving_binary=self._serving_binary,
             serving_spec=self._serving_spec,
             validation_spec=self._validation_spec,
             requests=[])
Esempio n. 3
0
    def testDo_MakeSavedModelWarmup(self):
        infra_validator = executor.Executor(self._context)
        self._request_spec.make_warmup = True
        self._exec_properties[standard_component_specs.REQUEST_SPEC_KEY] = (
            proto_utils.proto_to_json(self._request_spec))

        with mock.patch.object(infra_validator, '_ValidateOnce'):
            infra_validator.Do(self._input_dict, self._output_dict,
                               self._exec_properties)

        warmup_file = path_utils.warmup_file_path(
            path_utils.stamped_model_path(self._blessing.uri))
        self.assertFileExists(warmup_file)
        self.assertEqual(self._blessing.get_int_custom_property('has_model'),
                         1)
Esempio n. 4
0
 def testValidateOnce_LoadAndQuery_Succeed(self):
   infra_validator = executor.Executor(self._context)
   with mock.patch.object(self._serving_binary,
                          'MakeClient') as mock_client_factory:
     mock_client = mock_client_factory.return_value
     with mock.patch.object(
         executor, '_create_model_server_runner') as mock_runner_factory:
       infra_validator._ValidateOnce(
           model_path=self._model_path,
           serving_binary=self._serving_binary,
           serving_spec=self._serving_spec,
           validation_spec=self._validation_spec,
           requests=['my_request'])
       mock_runner_factory.return_value.WaitUntilRunning.assert_called()
       mock_client.WaitUntilModelLoaded.assert_called()
       mock_client.SendRequests.assert_called()
Esempio n. 5
0
    def testDo_LoadOnly(self):
        # Prepare inputs and mocks.
        input_dict = self.input_dict.copy()
        input_dict.pop('examples')
        exec_properties = self.exec_properties.copy()
        exec_properties.pop('request_spec')
        self.model_server.WaitUntilModelAvailable.return_value = True

        # Run executor.
        infra_validator = executor.Executor(self.context)
        infra_validator.Do(input_dict, self.output_dict, exec_properties)

        # Check output artifact.
        self.assertFileExists(os.path.join(self.blessing.uri, 'INFRA_BLESSED'))
        self.assertEqual(1, self.blessing.get_int_custom_property('blessed'))

        # Check cleanup done.
        self.model_server.Stop.assert_called()
Esempio n. 6
0
    def testDo_LoadAndRequest(self):
        # Prepare inputs and mocks.
        requests = [mock.Mock()]
        self.build_requests_mock.return_value = requests
        self.model_server.WaitUntilModelAvailable.return_value = True
        self.model_server.client.IssueRequests.return_value = True

        # Run executor.
        infra_validator = executor.Executor(self.context)
        infra_validator.Do(self.input_dict, self.output_dict,
                           self.exec_properties)

        # Check output artifact.
        self.model_server.client.IssueRequests.assert_called_with(requests)
        self.assertFileExists(os.path.join(self.blessing.uri, 'INFRA_BLESSED'))
        self.assertEqual(1, self.blessing.get_int_custom_property('blessed'))

        # Check cleanup done.
        self.model_server.Stop.assert_called()