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 panic about float in storage port, and add a test that verifies it #501

Merged
merged 1 commit into from Aug 12, 2014
Merged

fix panic about float in storage port, and add a test that verifies it #501

merged 1 commit into from Aug 12, 2014

Conversation

natefinch
Copy link
Contributor

So, this fixes-1347715 - at least the most problem thing to crop up. We have tests in the code that were checking to make sure that if a float gets into the config via json deserialization, that we handle it correctly. However, it wasn't doing precisely the same thing the production code does, so it wasn't actually getting the value into the right area of the environConfig, and wasn't actually calling storagePort(). The test I added does this, and I verified it fails with a panic with the old code for manualConfig... then fixed the code the do a type assertion first, handling float64 and int... reran the test and now the test passes.

My only concern is that I don't know what changed to cause this error to suddenly start occurring. I'm going to look into it and see if I can find the change that revealed this error.

c.Assert(err, gc.IsNil)

// really, we're asserting that this doesn't panic :)
c.Assert(env.(*manualEnviron).cfg.storagePort(), gc.Equals, int(8040))
Copy link
Contributor

Choose a reason for hiding this comment

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

You could also use the gc.Panic/gc.PanicMatches checkers to test that it does panic when expected.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is the int cast on int(8040) necessary?

Copy link
Contributor

Choose a reason for hiding this comment

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

As far as I understand it, at the point gocheck compares the values go has already inferred a type from the literal: int. So the cast 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.

It really shouldn't ever be set to something that's not a float or an int.... the panic is basically just there in the cast because something has to happen there, and we can't return anything.

The cast to int is not necessary... the constant 8040 will default to becoming an int, but it does sort of make it a little more clear that the constant isn't getting implicitly cast to some other type (like float64).

@cmars
Copy link
Contributor

cmars commented Aug 12, 2014

LGTM

@natefinch
Copy link
Contributor Author

$$itAintGonnaFixItself$$

@jujubot
Copy link
Collaborator

jujubot commented Aug 12, 2014

Status: merge request accepted. Url: http://juju-ci.vapour.ws:8080/job/github-merge-juju

@jujubot
Copy link
Collaborator

jujubot commented Aug 12, 2014

Build failed: Does not match ['fixes-1347715', 'fixes-1355324']
build url: http://juju-ci.vapour.ws:8080/job/github-merge-juju/272

@natefinch
Copy link
Contributor Author

weird, $$fixes-1347715$$

@jujubot
Copy link
Collaborator

jujubot commented Aug 12, 2014

Status: merge request accepted. Url: http://juju-ci.vapour.ws:8080/job/github-merge-juju

jujubot added a commit that referenced this pull request Aug 12, 2014
fix panic about float in storage port, and add a test that verifies it

So, this __fixes-1347715__ - at least the most problem thing to crop up.  We have tests in the code that were checking to make sure that if a float gets into the config via json deserialization, that we handle it correctly.  However, it wasn't doing precisely the same thing the production code does, so it wasn't actually getting the value into the right area of the environConfig, and wasn't actually calling storagePort().  The test I added does this, and I verified it fails with a panic with the old code for manualConfig... then fixed the code the do a type assertion first, handling float64 and int... reran the test and now the test passes.

My only concern is that I don't know what changed to cause this error to suddenly start occurring.  I'm going to look into it and see if I can find the change that revealed this error.
@jujubot jujubot merged commit e763bc1 into juju:master Aug 12, 2014
@axw
Copy link
Contributor

axw commented Aug 13, 2014

We should be using the schema package's coercion, but this will do for now I suppose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants