Skip to content
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 Document.initAction to fire when opening from the IDE #4582

Merged
merged 6 commits into from
Jan 18, 2020

Conversation

jamshark70
Copy link
Contributor

@jamshark70 jamshark70 commented Sep 18, 2019

Purpose and Motivation

Fixes #4549.

Previously, Document.initAction = { ... } or autorun documents took effect only when opening the document programmatically (Document.open or Document.new), but these were ignored when opening the document using IDE menu commands.

The simplest fix also means that autoRun documents will execute whenever recompiling the class library (if they are open). Per discussion under #4549, this seems to match the original autoRun behavior under Cocoa, and it's justifiable as an easy way to write "soft" startup code. However, the documentation inaccurately claimed that autoRun fires only when opening the document. So I updated the help file as well.

This PR touches two behaviors that are impossible to test automatically:

  • User action in the IDE.
  • Startup behavior after recompiling the library (as this would halt the entire test suite).

I've added tests for initAction and autoRun when opening a document programmatically. That's about all I think I can do.

Types of changes

  • Documentation
  • Bug fix

To-do list

  • Code is tested
  • All tests are passing
  • Updated documentation
  • This PR is ready for review

@jamshark70 jamshark70 added the comp: class library SC class library label Sep 18, 2019
@joshpar joshpar requested a review from dyfer September 29, 2019 19:53
Copy link
Member

@dyfer dyfer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks good to me. /*RUN*/ works when opening the document and when recompiling library, unit test passes, documentation is updated to match the fixed behavior.

nhthn
nhthn previously requested changes Dec 15, 2019
Copy link
Contributor

@nhthn nhthn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks! some comments mostly on testing.

};
this.assert(success, "Document.new should fire Document.initAction function");
} {
this.assert(false, "Cannot test Document.new behavior in a non-ScIDE session");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UnitTest doesn't have a built-in mechanism for marking a test as "skip", but borrowing semantics from other test frameworks, i would expect this to pass, not fail. if we put an "assert false" in here, the test suite will always fail if you are running in an environment without the IDE, which doesn't seem right to me.

i'd suggest replacing this assertion with an empty code block with a comment like // TODO: skip this test when UnitTest has skip functionality

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, fair enough. Should there or should there not be some record of tests that were skipped, and why, in a given run? Eventually yes, I suppose.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just remembered there's an open ticket for this: #4384. i propose adding // TODO: skip to all skipped tests so we can easily grep for them later when test skipping is implemented.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

protect {
Document.initAction = { success = true };
doc = Document.new;
0.1.wait;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.1.wait in a test is a code smell. can you justify why this is necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normal way to handle asynchronicity is with a condition.hang in the async response (initAction here). But we are testing whether the initAction fired or not. Therefore there is some reasonable expectation that the initAction may fail to fire. In that case, the Condition never unhangs and voilà, the entire test suite has ground to a halt.

This situation is impossible to test without a timeout. So, please advise what is the interface provided by the UnitTest suite for asynchronicity with timeout, and I'll very happily update (as I've been waiting years for that interface).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW I've started working on a Condition:hangWithTimeout so that this might not be a problem in the future.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't work a lot with UnitTest, but i think it's UnitTest:wait? if that doesn't work, leaving in the 0.1.wait is fine as long as there is a comment justifying it for anyone looking at the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, but there is #3895. Well, what to do. I'll email the dev list.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you try UnitTest:wait and see if it works here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, UnitTest:wait is better. I didn't know about that one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW fixed 10 days ago. AFAICS this is ready to go?

testsuite/classlibrary/TestDocument.sc Show resolved Hide resolved
@telephon
Copy link
Member

telephon commented Dec 16, 2019

BTW I've started working on a Condition:hangWithTimeout so that this might not be a problem in the future.

There was a discussion about this in the past. I remember that the result was that you can just write .hang(0.5) or whatever time you want as timeout, and that it was a documentation issue.

@jamshark70
Copy link
Contributor Author

There was a discussion about this in the past. I remember that the result was that you can just write .hang(0.5) or whatever time you want as timeout, and that it was a documentation issue.

That discussion eventually rejected that solution.

(
r = fork {
	var c = Condition.new,
	resp = OSCFunc({ c.unhang }, '/test'),
	now;
	thisThread.clock.sched(0.25, {
		"let's pretend we got an async reply in 0.25 sec".postln;
		NetAddr.localAddr.sendMsg("/test");
	});
	c.hang(2);
	now = thisThread.beats;
	loop {
		(thisThread.beats - now).debug("beats since unhanging");
		1.0.wait;
	};
};
)

let's pretend we got an async reply in 0.25 sec
beats since unhanging: 0.0
beats since unhanging: 1.0
beats since unhanging: 1.74982049
beats since unhanging: 2.0
beats since unhanging: 2.74982049

r.stop;

@jamshark70 jamshark70 mentioned this pull request Dec 26, 2019
4 tasks
The user may set PathName.tmp, potentially dangerous in testing
Copy link
Contributor

@mossheim mossheim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! thanks

}

test_open_autorun_document_runs_code {
var path = Platform.defaultTempDir +/+ "autoRunTest%.scd".format(UniqueID.next),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the intent here with UniqueID.next?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I think my intent was to reduce the likelihood of crashing into a leftover file in the temp directory. But UniqueID probably wouldn't work for that.

I'll just take it out.

@telephon telephon requested a review from nhthn January 6, 2020 16:58
@mossheim mossheim changed the base branch from 3.10 to develop January 18, 2020 01:55
@mossheim mossheim dismissed nhthn’s stale review January 18, 2020 01:55

changes addressed

@mossheim mossheim merged commit 706229f into supercollider:develop Jan 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp: class library SC class library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Document.initAction not called from the editor
5 participants