Skip to content

SourceKit: use std::chrono in unittests #22058

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

Merged
merged 1 commit into from
Jan 24, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions unittests/SourceKit/SwiftLang/EditingTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@
#include "llvm/Support/Path.h"
#include "llvm/Support/TargetSelect.h"
#include "gtest/gtest.h"
#include <mutex>

#include <chrono>
#include <condition_variable>
#include <mutex>
#include <thread>

using namespace SourceKit;
using namespace llvm;
Expand Down Expand Up @@ -177,7 +180,7 @@ class EditTest : public ::testing::Test {
DocUpdState->HasUpdate = false;
}

void doubleOpenWithDelay(useconds_t delay, bool close);
void doubleOpenWithDelay(std::chrono::microseconds delay, bool close);

private:
std::vector<const char *> makeArgs(const char *DocName,
Expand Down Expand Up @@ -229,7 +232,8 @@ TEST_F(EditTest, DiagsAfterEdit) {
EXPECT_EQ(SemaDiagStage, Consumer.DiagStage);
}

void EditTest::doubleOpenWithDelay(useconds_t delay, bool closeDoc) {
void EditTest::doubleOpenWithDelay(std::chrono::microseconds delay,
bool closeDoc) {
const char *DocName = "/test.swift";
const char *Contents =
"func foo() { _ = unknown_name }\n";
Expand All @@ -239,8 +243,8 @@ void EditTest::doubleOpenWithDelay(useconds_t delay, bool closeDoc) {
open(DocName, Contents, Args, Consumer);
ASSERT_EQ(0u, Consumer.Diags.size());
// Open again without closing; this reinitializes the semantic info on the doc
if (delay)
usleep(delay);
if (delay > std::chrono::microseconds(0))
std::this_thread::sleep_for(delay);
if (closeDoc)
close(DocName);
reset(Consumer);
Expand Down Expand Up @@ -277,19 +281,19 @@ TEST_F(EditTest, DISABLED_DiagsAfterCloseAndReopen) {
// The middle case in particular verifies the ASTManager is only calling the
// correct ASTConsumers.

doubleOpenWithDelay(0, true);
doubleOpenWithDelay(1000, true); // 1 ms
doubleOpenWithDelay(10000, true); // 10 ms
doubleOpenWithDelay(100000, true); // 100 ms
doubleOpenWithDelay(std::chrono::microseconds(0), true);
doubleOpenWithDelay(std::chrono::milliseconds(1), true);
doubleOpenWithDelay(std::chrono::milliseconds(10), true);
doubleOpenWithDelay(std::chrono::milliseconds(100), true);
}

TEST_F(EditTest, DiagsAfterReopen) {
// See description of DiagsAfterCloseAndReopen, but in this case we don't
// close the original document, causing it to reinitialize instead of create
// a fresh document.

doubleOpenWithDelay(0, false);
doubleOpenWithDelay(1000, false); // 1 ms
doubleOpenWithDelay(10000, false); // 10 ms
doubleOpenWithDelay(100000, false); // 100 ms
doubleOpenWithDelay(std::chrono::microseconds(0), false);
doubleOpenWithDelay(std::chrono::milliseconds(1), false);
doubleOpenWithDelay(std::chrono::milliseconds(10), false);
doubleOpenWithDelay(std::chrono::milliseconds(100), false);
}