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

tcpproxy: add pause and resume to the stream #119

Merged
merged 1 commit into from
Feb 3, 2017

Conversation

mhilton
Copy link
Contributor

@mhilton mhilton commented Feb 3, 2017

This allows servers that are not responding in a timely manner to be
simulated.

Copy link
Contributor

@rogpeppe rogpeppe 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

tcpproxy.go Outdated
@@ -33,6 +38,7 @@ func NewTCPProxy(c *gc.C, remoteAddr string) *TCPProxy {
p := &TCPProxy{
listener: listener,
}
p.stopStart = sync.NewCond(&p.mu)
Copy link
Contributor

Choose a reason for hiding this comment

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

Or, if you declare stopStart as a value not a pointer, then:

p.stopStart.L = &p.mu

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

tcpproxy.go Outdated
@@ -91,6 +97,24 @@ func (p *TCPProxy) CloseConns() {
}
}

// PauseConns stops traffic flowing through all the connections that are
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, it pauses all traffic, so perhaps:

// PauseConns stops all traffic flowing through the proxy.

?

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

tcpproxy.go Outdated
io.Copy(dst, src)
buf := make([]byte, 32*1024)
for {
nr, er := src.Read(buf)
Copy link
Contributor

Choose a reason for hiding this comment

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

Since you're not bothered about the actual errors, I'd name the error variables just as conventional "err".

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

@@ -140,3 +177,15 @@ func assertEOF(c *gc.C, r io.Reader) {
c.Assert(err, gc.Equals, io.EOF)
c.Assert(n, gc.Equals, 0)
}

func assertReadTimeout(c *gc.C, conn net.Conn) {
err := conn.SetReadDeadline(time.Now().Add(500 * time.Millisecond))
Copy link
Contributor

Choose a reason for hiding this comment

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

nice

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks

This allows servers that are not responding in a timely manner to be
simulated.
@mhilton mhilton force-pushed the 001-tcpproxy-pause branch from e810f2f to b567b5e Compare February 3, 2017 17:35
@mhilton
Copy link
Contributor Author

mhilton commented Feb 3, 2017

$$merge$$

@jujubot
Copy link
Contributor

jujubot commented Feb 3, 2017

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

@jujubot jujubot merged commit d2f0674 into juju:master Feb 3, 2017
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.

4 participants