You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

task_manager_test.cc 1.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /**
  2. * Copyright 2019 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include "common/common.h"
  17. #include "gtest/gtest.h"
  18. #include "dataset/util/task_manager.h"
  19. using namespace mindspore::dataset;
  20. using namespace std::placeholders;
  21. class MindDataTestTaskManager : public UT::Common {
  22. public:
  23. MindDataTestTaskManager() {}
  24. void SetUp() { Services::CreateInstance();
  25. }
  26. };
  27. std::atomic<int> v(0);
  28. Status f(TaskGroup &vg){
  29. for (int i = 0; i < 1; i++) {
  30. RETURN_IF_NOT_OK(vg.CreateAsyncTask("Infinity", [&]() -> Status {
  31. TaskManager::FindMe()->Post();
  32. int a = v.fetch_add(1);
  33. MS_LOG(DEBUG) << a << std::endl;
  34. return f(vg);
  35. }));
  36. }
  37. return Status::OK();
  38. }
  39. TEST_F(MindDataTestTaskManager, Test1) {
  40. // Clear the rc of the master thread if any
  41. (void) TaskManager::GetMasterThreadRc();
  42. TaskGroup vg;
  43. Status vg_rc = vg.CreateAsyncTask("Test error", [this]() -> Status {
  44. TaskManager::FindMe()->Post();
  45. throw std::bad_alloc();
  46. });
  47. ASSERT_TRUE(vg_rc.IsOk() || vg_rc.IsOutofMemory());
  48. ASSERT_TRUE(vg.join_all().IsOk());
  49. ASSERT_TRUE(vg.GetTaskErrorIfAny().IsOutofMemory());
  50. // Test the error is passed back to the master thread.
  51. Status rc = TaskManager::GetMasterThreadRc();
  52. ASSERT_TRUE(rc.IsOutofMemory());
  53. }