Unverified Commit 113be5a8 by Dane Springmeyer Committed by GitHub

Merge pull request #1009 from mapbox/revert-1007-experimental-worker

Revert "Add support for running inside a node 10.5 worker_thread"
parents 36ec8cf0 ffc1c219
......@@ -50,8 +50,7 @@
"prepublishOnly": "npm ls",
"install": "node-pre-gyp install --fallback-to-build",
"pretest": "node test/support/createdb.js",
"test": "mocha -R spec --timeout 480000",
"test:worker": "node --experimental-worker scripts/mocha-as-worker.js -R spec --timeout 480000"
"test": "mocha -R spec --timeout 480000"
},
"license": "BSD-3-Clause",
"keywords": [
......
// Run the mocha tests in a worker
// Not a clean approach, but is sufficient to verify correctness
const worker_threads = require("worker_threads");
const path = require("path");
if (worker_threads.isMainThread) {
const worker = new worker_threads.Worker(__filename, { workerData: { windowSize: process.stdout.getWindowSize() } });
worker.on("error", console.error);
} else {
process.stdout.getWindowSize = () => worker_threads.workerData.windowSize;
const mochaPath = path.resolve(require.resolve("mocha"), "../bin/_mocha");
require(mochaPath);
}
......@@ -22,11 +22,11 @@ public:
Parent* parent;
public:
Async(uv_loop_t* loop_, Parent* parent_, Callback cb_)
Async(Parent* parent_, Callback cb_)
: callback(cb_), parent(parent_) {
watcher.data = this;
NODE_SQLITE3_MUTEX_INIT
uv_async_init(loop_, &watcher, reinterpret_cast<uv_async_cb>(listener));
uv_async_init(uv_default_loop(), &watcher, reinterpret_cast<uv_async_cb>(listener));
}
static void listener(uv_async_t* handle, int status) {
......
......@@ -127,12 +127,7 @@ NAN_METHOD(Database::New) {
callback = Local<Function>::Cast(info[pos++]);
}
#if NODE_MODULE_VERSION > NODE_9_0_MODULE_VERSION
uv_loop_t* loop = node::GetCurrentEventLoop(info.GetIsolate());
#else
uv_loop_t* loop = uv_default_loop();
#endif
Database* db = new Database(loop);
Database* db = new Database();
db->Wrap(info.This());
Nan::ForceSet(info.This(), Nan::New("filename").ToLocalChecked(), info[0].As<String>(), ReadOnly);
......@@ -146,7 +141,7 @@ NAN_METHOD(Database::New) {
}
void Database::Work_BeginOpen(Baton* baton) {
int status = uv_queue_work(baton->db->loop,
int status = uv_queue_work(uv_default_loop(),
&baton->request, Work_Open, (uv_after_work_cb)Work_AfterOpen);
assert(status == 0);
}
......@@ -232,7 +227,7 @@ void Database::Work_BeginClose(Baton* baton) {
baton->db->RemoveCallbacks();
baton->db->closing = true;
int status = uv_queue_work(baton->db->loop,
int status = uv_queue_work(uv_default_loop(),
&baton->request, Work_Close, (uv_after_work_cb)Work_AfterClose);
assert(status == 0);
}
......@@ -393,7 +388,7 @@ void Database::RegisterTraceCallback(Baton* baton) {
if (db->debug_trace == NULL) {
// Add it.
db->debug_trace = new AsyncTrace(db->loop, db, TraceCallback);
db->debug_trace = new AsyncTrace(db, TraceCallback);
sqlite3_trace(db->_handle, TraceCallback, db);
}
else {
......@@ -431,7 +426,7 @@ void Database::RegisterProfileCallback(Baton* baton) {
if (db->debug_profile == NULL) {
// Add it.
db->debug_profile = new AsyncProfile(db->loop, db, ProfileCallback);
db->debug_profile = new AsyncProfile(db, ProfileCallback);
sqlite3_profile(db->_handle, ProfileCallback, db);
}
else {
......@@ -472,7 +467,7 @@ void Database::RegisterUpdateCallback(Baton* baton) {
if (db->update_event == NULL) {
// Add it.
db->update_event = new AsyncUpdate(db->loop, db, UpdateCallback);
db->update_event = new AsyncUpdate(db, UpdateCallback);
sqlite3_update_hook(db->_handle, UpdateCallback, db);
}
else {
......@@ -527,7 +522,7 @@ void Database::Work_BeginExec(Baton* baton) {
assert(baton->db->open);
assert(baton->db->_handle);
assert(baton->db->pending == 0);
int status = uv_queue_work(baton->db->loop,
int status = uv_queue_work(uv_default_loop(),
&baton->request, Work_Exec, (uv_after_work_cb)Work_AfterExec);
assert(status == 0);
}
......@@ -627,7 +622,7 @@ void Database::Work_BeginLoadExtension(Baton* baton) {
assert(baton->db->open);
assert(baton->db->_handle);
assert(baton->db->pending == 0);
int status = uv_queue_work(baton->db->loop,
int status = uv_queue_work(uv_default_loop(),
&baton->request, Work_LoadExtension, reinterpret_cast<uv_after_work_cb>(Work_AfterLoadExtension));
assert(status == 0);
}
......
......@@ -100,9 +100,8 @@ public:
friend class Statement;
protected:
Database(uv_loop_t* loop_) : Nan::ObjectWrap(),
Database() : Nan::ObjectWrap(),
_handle(NULL),
loop(loop_),
open(false),
closing(false),
locked(false),
......@@ -173,10 +172,7 @@ protected:
protected:
sqlite3* _handle;
public:
uv_loop_t* loop;
protected:
bool open;
bool closing;
bool locked;
......
......@@ -122,7 +122,7 @@ const char* sqlite_authorizer_string(int type);
assert(baton->stmt->prepared); \
baton->stmt->locked = true; \
baton->stmt->db->pending++; \
int status = uv_queue_work(baton->stmt->db->loop, \
int status = uv_queue_work(uv_default_loop(), \
&baton->request, \
Work_##type, reinterpret_cast<uv_after_work_cb>(Work_After##type)); \
assert(status == 0);
......
......@@ -115,7 +115,7 @@ NAN_METHOD(Statement::New) {
void Statement::Work_BeginPrepare(Database::Baton* baton) {
assert(baton->db->open);
baton->db->pending++;
int status = uv_queue_work(baton->db->loop,
int status = uv_queue_work(uv_default_loop(),
&baton->request, Work_Prepare, (uv_after_work_cb)Work_AfterPrepare);
assert(status == 0);
}
......
......@@ -174,7 +174,7 @@ public:
watcher.data = this;
NODE_SQLITE3_MUTEX_INIT
stmt->Ref();
uv_async_init(stmt->db->loop, &watcher, async_cb);
uv_async_init(uv_default_loop(), &watcher, async_cb);
}
~Async() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment