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

Refactor the HTTP handler into a struct #6

Open
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

jameinel
Copy link

This changes the 'handler' from being just a func() using global state to being a struct with local state.
It then moves the things like dev and log to being members of the struct, with interfaces that let us override them in the test suite.
It then adds a bunch of tests about how we handle failures, errors, logging, the size flag, etc.
The interfaces also mean that we won't try to spam syslog while running the test suite.

Another small change is that if you do:

    pollen -https-port=""

Then it won't try to bind to the HTTP port with a cert.
Since I'm not the official source for pollen, it helped for testing at least the HTTP requests manually.

This also fixes the help text for "-size" since it doesn't actually change how much content we send on the wire, but how much content we read from /dev/urandom (but it adds tests for that fact).

This allows the test suite to not spam syslog while testing.
It will also let us test that messages actually get logged, etc.
This makes it easier to test the actual binary (for me at least)
Use a WaitGroup so that we wait for whatever we *do* run.
This makes it easier to test the actual binary (for me at least)
Use a WaitGroup so that we wait for whatever we *do* run.
It is nice to know how the random data is handled.
Test that we actually get an error code in the no-challenge case.
Test that we handle when we can't write to the device.
Test that we fail and log a message when we can't read from the device,
and we send the appropriate message across the wire.
when using fatal it wasn't appending a newline, so messages were confusing
this fixes that.
also, add millisecond-level timing for how long it takes us to respond
to requests. The *data* is available in UnixNano() but it requires
doing the subtraction somehow, and also misses some of the overhead
as the 'received challenge' only triggers after we've processed
some of the request.
also, add a log when the process starts
@dustinkirkland
Copy link
Owner

Looks brilliant, thanks!

Committed and pushed to both bzr and git.

kirkland@x230:~/src/pollen/pollen⟫ debcommit
bzr commit -m '* .gitignore, pollen.go, pollen_test.go:

  • This changes the 'handler' from being just a func() using global
    state to being a struct with local state.
  • It then moves the things like dev and log to being members of the
    struct, with interfaces that let us override them in the test suite.
  • It then adds a bunch of tests about how we handle failures, errors,
    logging, the size flag, etc.
  • The interfaces also mean that we won't try to spam syslog while running
    the test suite.
  • Another small change is that if you do:
    pollen -https-port=""
    Then it won't try to bind to the HTTP port with a cert.
  • Since I'm not the official source for pollen, it helped for testing at
    least the HTTP requests manually.
  • This also fixes the help text for "-size" since it doesn't actually
    change how much content we send on the wire, but how much content we
    read from /dev/urandom (but it adds tests for that fact).'
    Committing to: /home/local/media/source/pollen/pollen/

added .gitignore
modified pollen.go
modified pollen_test.go
modified debian/changelog
Committed revision 272.
kirkland@x230:~/src/pollen/pollen⟫ multi-push
INFO: bzr exists
Using saved push location: bzr+ssh://bazaar.launchpad.net/+branch/pollen/
Pushed up to revision 272.

INFO: git exists
10:30:21 Calculating the revisions to include ...
10:30:21 Starting export of 286 revisions ...
10:30:21 Exported 286 revisions in 0:00:00
warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:

git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

git config --global push.default simple

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)

Counting objects: 12, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (7/7), 5.63 KiB | 0 bytes/s, done.
Total 7 (delta 5), reused 3 (delta 1)
To [email protected]:dustinkirkland/pollen.git
f3a684b..f026a08 master -> master

Dustin Kirkland
Canonical, Ltd.

On Wed, Feb 26, 2014 at 3:06 AM, John Arbash Meinel <
[email protected]> wrote:

This changes the 'handler' from being just a func() using global state to
being a struct with local state.
It then moves the things like dev and log to being members of the struct,
with interfaces that let us override them in the test suite.
It then adds a bunch of tests about how we handle failures, errors,
logging, the size flag, etc.
The interfaces also mean that we won't try to spam syslog while running
the test suite.

Another small change is that if you do:

pollen -https-port=""

Then it won't try to bind to the HTTP port with a cert.
Since I'm not the official source for pollen, it helped for testing at
least the HTTP requests manually.

This also fixes the help text for "-size" since it doesn't actually change
how much content we send on the wire, but how much content we read from

/dev/urandom (but it adds tests for that fact).

You can merge this Pull Request by running

git pull https://github.com/jameinel/pollen struct-refactor

Or view, comment on, or merge it at:

#6
Commit Summary

  • Move the handler into a struct
  • Move the dev object as an io.ReadWriter attribute of the server
  • abstract the logging behind an interface
  • fix the size help text
  • allow disabling https-port or http-port by passing ""
  • allow disabling https-port or http-port by passing ""
  • go fmt and test with canned data
  • Assert that changing the size actually changes how the backend works.
  • more error message testing

File Changes

Patch Links:


Reply to this email directly or view it on GitHubhttps://github.com//pull/6
.

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

Successfully merging this pull request may close these issues.

2 participants