[testbox] How do I invalid/cycle the session scope in a test?

I have a component which should exist in the session scope, i.e.

...

I am writing a test to verify that the object is tied to a session:

var ObjA = Wirebox.getInstance(‘ObjName’);
var ObjB = Wirebox.getInstance(‘ObjName’);

assertSame( ObjA , ObjB , “Expected same instance to be returned.” );

SessionInvalidate();

var ObjC = Wirebox.getInstance(‘ObjName’);
var ObjD = Wirebox.getInstance(‘ObjName’);

assertNotSame( ObjC , ObjB , “Expected new instance to be created.” );
assertSame( ObjC , ObjD , “Expected same instance to be returned.” );

The assertNotSame is failing, because ObjB and ObjC are the same.

Is this an issue with SessionInvalidate or do I need to do something at a Coldbox level for this?

Ok, on further testing it seems the SessionInvalidate is ok, and the problem is with assertNotSame

That is, if I dump the local scope I get:

OBJ A
component path.to.ObjName
UUID BD556258-CD84-0F57-C84682E70B823771
$MIXED true
METHODS

OBJB [see cfc1 for ObjName details]

OBJC
component path.to.ObjName
$MIXED true
UUID BD556950-0329-A57C-56F198F5DB9BA85C
METHODS

OBJD [see cfc2 for ObjName details]

So the code is doing what it should, and it is the assertion that is failing.

The problem is because assertSame/assertNotSame is simply deferring to isEquals/isNotEquals, this calling an “equalize” function which treats objects as structs and simply compares the public variables.

This is INCORRECT behaviour for assertSame/assertNotSame (they should be equivalent to the === and !== operators in JavaScript), so a bug in TestBox.

they should be equivalent to the === and !== operators in JavaScript

And of course the === and !== operators in Railo - but unfortunately, this code is currently CF10 so I can’t just use those.

The workaround is:

var System = createObject(‘java’,‘java.lang.System’);
assertEquals( System.identityHashCode(ObjA) , System.identityHashCode(ObjB) );

I created the above workaround as a custom assertion, for the benefit of anyone else who has the same problem (at least before TestBox is fixed/released).

Custom Assertion code is here:

Save that to a file, e.g. in {root-dir}/testing/assertions/Component.cfc then in setup() or beforeTests() refer to it like this:

addAssertions( new testing.assertions.Component() );

Then you can use it like so:

var ObjA = Wirebox.getInstance(‘ObjName’);
var ObjB = Wirebox.getInstance(‘ObjName’);

$assert.isSameInstance( ObjA , ObjB , “Expected same instance to be returned.” );

SessionInvalidate();

var ObjC = Wirebox.getInstance(‘ObjName’);
var ObjD = Wirebox.getInstance(‘ObjName’);

$assert.isNotSameInstance( ObjC , ObjB , “Expected new instance to be created.” );
$assert.isSameInstance( ObjC , ObjD , “Expected same instance to be returned.” );

Thanks for the research on this. There’s actually ticket that was put in for this yesterday:

https://ortussolutions.atlassian.net/browse/TESTBOX-76

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Any plans / thoughts on when the next Testbox release is aimed for?

On a side note, are there any Groups Admin options to stop Google changing “testbox” to “textbox” when searching? Even writing +“testbox” is getting changed now, which used to be the way to tell it to stop buggering about with what I’ve told it to look for.
(I’m thinking maybe if there’s a keywords option or similar, that might be enough to stop it.)

Searching testbox works for me

Searching testbox works for me

This is what I get:

Bizarre, wonder if there is some recognition based off previous searches going on here.

If it is, it’s a recognition on your side - I tried both logged in and logged out (incognito, so should be no cookies involved) and got same results.

But then it doesn’t pay attention to searches in the same session - i.e. altered or even repeated searches still get changed (despite selecting the proper term) every time, which I would expect to be more likely than basing of searches from previous sessions? :confused:

But yeah, this is why I was wondering about an admin option for keywords though - maybe it takes those into account for whether it shows “corrections”, and thus adding testbox in might stop it changing. (I think the Google Custom Search Engine stuff has something like that, but that might be entirely different to Groups search.)

Do not know what to say, for me the search results are testbox on my
Windows 8, laptop also running windows 8 and 3 Virtual Box instances
(Running Windows 7, Windows Server 2003 / 2012) all resulted for the same
as me.

Regards,
Andrew Scott
WebSite: http://www.andyscott.id.au/
Google+: http://plus.google.com/113032480415921517411

I get the same thing you do Peter. I think it’s just Google trying to “help” and I’ve never seen any settings to change it. I just have to click the “search instead for testbox” link.

Sometimes on Google’s web search, I’ll put stuff in quotes and under search tools, change to “verbatim”, but I don’t see those options on Google Groups.

According to this video, there’s nothing you can do about it:

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

According to this video, there's nothing you can do about it:

Oh I dunno, I expect a murderous rampage through Mountain View is something
I could potentially do... :confused:

Backs away slowly, avoiding eye contact :slight_smile:

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

lol

Btw I know this is an old thread, if you want to know how major online searches social networks work to personalise your experience. You may find this 3 year old talk on Ted interesting.

https://www.youtube.com/watch?v=bOE1HFEL8XA