-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix the order of callback by performFunctionInCocosThread and add unit-test for it. #17543
Merged
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
6a941e7
Fix the order of callback by performFunctionInCocosThread and add uni…
dumganhar 80736f9
Update license.
dumganhar 3231bdc
Use std::this_thread::sleep_for
dumganhar dce2e37
Try fix ci error
dumganhar 88e0adc
Update scheduler_test.cpp
dumganhar 07beedc
Remove other unit test to figure out
dumganhar 2739895
Update
dumganhar f45fc8e
Revert "Update"
dumganhar fcb1a8c
Revert "Remove other unit test to figure out"
dumganhar e6328bc
Revert "Update scheduler_test.cpp"
dumganhar 2b4c145
Use macOS to run unittest
dumganhar 447c7c3
Update path
dumganhar de8a621
Print cmake version
dumganhar 95cb37a
Use cmake 3.24.3
dumganhar ab2a432
Update
dumganhar f8b82e4
Update
dumganhar 1413690
Update cmake to 3.28.3 for unittest
dumganhar a554df9
Use xcodebuild instead of cmake --build to fix cmake bug: clang: erro…
dumganhar c9ac9c8
Update
dumganhar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/**************************************************************************** | ||
Copyright (c) 2014-2016 Chukong Technologies Inc. | ||
Copyright (c) 2017-2023 Xiamen Yaji Software Co., Ltd. | ||
|
||
http://www.cocos.com | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | ||
of the Software, and to permit persons to whom the Software is furnished to do so, | ||
subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
****************************************************************************/ | ||
#include <vector> | ||
|
||
#include "base/Scheduler.h" | ||
#include "utils.h" | ||
|
||
using namespace cc; | ||
|
||
TEST(schedulerTest, performInCocosThreadOrder) { | ||
auto scheduler = std::make_shared<Scheduler>(); | ||
|
||
std::vector<int> orderResult; | ||
|
||
for (int i = 0; i < 10; ++i) { | ||
auto task = [&orderResult, i, &scheduler](){ | ||
orderResult.emplace_back(i); | ||
|
||
if (i == 5) { | ||
scheduler->performFunctionInCocosThread([&orderResult](){ | ||
orderResult.emplace_back(10); | ||
}); | ||
|
||
scheduler->performFunctionInCocosThread([&orderResult](){ | ||
orderResult.emplace_back(11); | ||
}); | ||
|
||
scheduler->performFunctionInCocosThread([&orderResult](){ | ||
orderResult.emplace_back(12); | ||
}); | ||
|
||
usleep(100 * 1000); | ||
} | ||
}; | ||
scheduler->performFunctionInCocosThread(task); | ||
} | ||
|
||
scheduler->runFunctionsToBePerformedInCocosThread(); | ||
scheduler->runFunctionsToBePerformedInCocosThread(); | ||
|
||
const std::vector<int> expectedResult{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; | ||
EXPECT_EQ(orderResult, expectedResult); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Consider using a thread-safe container for orderResult to prevent potential race conditions