-
Notifications
You must be signed in to change notification settings - Fork 390
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
JS: Remove dead state transition validation code #1771
Conversation
Soooo, because `this.state` was initialised to `null` and not 'start', this code was always actually dead. `validateStateTransition` had no branch for `oldState` being null, so always returned `false`. This meant `this.state` was *never* set to current state, and so in all callbacks, `oldState` was always `null`! I validated this again by console.logging `oldState` and `newState` inside `validateStateTransition`. Here's the output for when a full build is performed: ``` null -> waiting null -> fetching null -> unknown null -> building null -> failed null -> built null -> launching ``` And for when launching a previously built image ``` null -> launching null -> ready ``` I also put one just above where `this.state` is set, and that code was never called. I was hoping to remove all this code anyway, as it doesn't actually validate nor test anything - that's really done by unit tests and integration tests. I thought this would hide bugs - but turns out, it was a bug itself, and hid nothing. This also changes the signature of the callback for `onChangeState`, dropping `oldState` and `newState`. `oldState` was always `null`, and in our code, we actually don't use `newState` *at all*. The one place that was conditional on `oldState` being null is now unconditional, because `oldState` was always `null`. Ref jupyterhub#774
This is one way to get to 100% unit test coverage - just find code that was never used and get rid of it :) |
Wieee thank you for working this @yuvipanda! |
jupyterhub/binderhub#1771 Merge pull request #1771 from yuvipanda/dead-code
} | ||
image.onStateChange('built', function() { | ||
$('#phase-already-built').removeClass('hidden'); | ||
$('#phase-launching').removeClass('hidden'); | ||
$('#phase-launching').removeClass('hidden'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is a duplicate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Soooo, because
this.state
was initialised tonull
and not 'start', this code was always actually dead.validateStateTransition
had no branch foroldState
being null, so always returnedfalse
. This meantthis.state
was never set to current state, and so in all callbacks,oldState
was alwaysnull
!I validated this again by console.logging
oldState
andnewState
insidevalidateStateTransition
. Here's the output for when a full build is performed:And for when launching a previously built image
I also put one just above where
this.state
is set, and that code was never called.I was hoping to remove all this code anyway, as it doesn't actually validate nor test anything - that's really done by unit tests and integration tests. I thought this would hide bugs - but turns out, it was a bug itself, and hid nothing.
This also changes the signature of the callback for
onChangeState
, droppingoldState
andnewState
.oldState
was alwaysnull
, and in our code, we actually don't usenewState
at all. The one place that was conditional onoldState
being null is now unconditional, becauseoldState
was alwaysnull
.Ref #774