-
-
Notifications
You must be signed in to change notification settings - Fork 42
feat(worker): accept platform options under ios, deprecate iosPriority #470
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2185f91
feat(worker): accept platform options under ios, deprecate iosPriority
edusperoni 5360bc4
feat(worker): treat ios: null as an absent ios option
edusperoni cbbb97f
test(worker): give low quality-of-service workers time to boot on a l…
edusperoni d85eb2c
test(worker): stop waiting on a background-class thread to boot an is…
edusperoni 5958bf0
fix(worker): stop construction when an option getter throws
edusperoni 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,139 @@ | ||
| describe("Worker platform options", function () { | ||
| var entry = "./workerOptions/qosWorker.js"; | ||
|
|
||
| // Jasmine arms a spec's async timeout before calling it, so the interval | ||
| // has to be raised ahead of the spec, not inside it. A utility thread boots | ||
| // a whole isolate under throttled CPU and I/O; on a contended host that has | ||
| // taken well over 10 s. | ||
| var originalTimeout; | ||
| beforeEach(function () { | ||
| originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL; | ||
| jasmine.DEFAULT_TIMEOUT_INTERVAL = 120000; | ||
| }); | ||
| afterEach(function () { | ||
| jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout; | ||
| }); | ||
|
|
||
| var reportQos = function (options, done, check) { | ||
| var worker = options === undefined ? new Worker(entry) : new Worker(entry, options); | ||
| var settled = false; | ||
| var finish = function () { | ||
| if (settled) { | ||
| return; | ||
| } | ||
| settled = true; | ||
| worker.terminate(); | ||
| done(); | ||
| }; | ||
| // A throw inside either handler must still settle the spec and | ||
| // terminate the worker; Jasmine only guards the spec body itself. | ||
| worker.onmessage = function (msg) { | ||
| try { | ||
| check(msg.data.qos); | ||
| } finally { | ||
| finish(); | ||
| } | ||
| }; | ||
| worker.onerror = function (e) { | ||
| try { | ||
| expect(String(e && e.message ? e.message : e)).toBe("<no worker error>"); | ||
| } finally { | ||
| finish(); | ||
| } | ||
| }; | ||
| }; | ||
|
|
||
| // Background is deliberately absent: the system defines that class as work | ||
| // that may take minutes, and on a loaded host a background thread has not | ||
| // finished booting an isolate within two minutes. It is covered below | ||
| // without waiting on it. | ||
| var priorities = [ | ||
| ["userInteractive", NSQualityOfService.UserInteractive], | ||
| ["userInitiated", NSQualityOfService.UserInitiated], | ||
| ["default", NSQualityOfService.Default], | ||
| ["utility", NSQualityOfService.Utility] | ||
| ]; | ||
|
|
||
| priorities.forEach(function (pair) { | ||
| it("runs the worker thread at " + pair[0] + " quality of service", function (done) { | ||
| reportQos({ ios: { priority: pair[0] } }, done, function (qos) { | ||
| expect(qos).toBe(pair[1]); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| it("accepts background priority", function () { | ||
| var worker; | ||
| expect(function () { | ||
| worker = new Worker(entry, { ios: { priority: "background" } }); | ||
| }).not.toThrow(); | ||
| worker.terminate(); | ||
| }); | ||
|
|
||
| it("still honors the deprecated iosPriority option", function (done) { | ||
| reportQos({ iosPriority: "utility" }, done, function (qos) { | ||
| expect(qos).toBe(NSQualityOfService.Utility); | ||
| }); | ||
| }); | ||
|
|
||
| it("prefers ios.priority over iosPriority when both are given", function (done) { | ||
| reportQos({ ios: { priority: "userInteractive" }, iosPriority: "background" }, done, function (qos) { | ||
| expect(qos).toBe(NSQualityOfService.UserInteractive); | ||
| }); | ||
| }); | ||
|
|
||
| it("ignores unknown keys inside ios", function (done) { | ||
| reportQos({ ios: { priority: "utility", somethingElse: 42 } }, done, function (qos) { | ||
| expect(qos).toBe(NSQualityOfService.Utility); | ||
| }); | ||
| }); | ||
|
|
||
| it("starts a worker given no options at all", function (done) { | ||
| reportQos(undefined, done, function (qos) { | ||
| expect(typeof qos).toBe("number"); | ||
| }); | ||
| }); | ||
|
|
||
| it("treats ios: null like an absent ios", function (done) { | ||
| reportQos({ ios: null, iosPriority: "utility" }, done, function (qos) { | ||
| expect(qos).toBe(NSQualityOfService.Utility); | ||
| }); | ||
| }); | ||
|
|
||
| it("propagates the error thrown by an option getter", function () { | ||
| var boom = new Error("boom"); | ||
| var options = new Proxy({}, { | ||
| get: function (target, key) { | ||
| if (key === "ios") { | ||
| throw boom; | ||
| } | ||
| return undefined; | ||
| } | ||
| }); | ||
| var thrown; | ||
| try { | ||
| new Worker(entry, options); | ||
| } catch (e) { | ||
| thrown = e; | ||
| } | ||
| expect(thrown).toBe(boom); | ||
| }); | ||
|
|
||
| it("throws a TypeError when ios is not an object", function () { | ||
| expect(function () { | ||
| new Worker(entry, { ios: 42 }); | ||
| }).toThrowError(TypeError, /"ios"/); | ||
| }); | ||
|
|
||
| it("throws a TypeError for an unknown ios.priority", function () { | ||
| expect(function () { | ||
| new Worker(entry, { ios: { priority: "highest" } }); | ||
| }).toThrowError(TypeError, /"ios\.priority"/); | ||
| }); | ||
|
|
||
| it("throws a TypeError for a non-string ios.priority", function () { | ||
| expect(function () { | ||
| new Worker(entry, { ios: { priority: 3 } }); | ||
| }).toThrowError(TypeError, /"ios\.priority"/); | ||
| }); | ||
| }); | ||
This file contains hidden or 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 hidden or 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,4 @@ | ||
| // Entry for WorkerOptionsTests: reports the quality of service the runtime | ||
| // gave this worker's thread, which is the only observable effect of the | ||
| // `ios.priority` option. | ||
| postMessage({ qos: NSThread.currentThread.qualityOfService }); |
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.
Uh oh!
There was an error while loading. Please reload this page.