Skip to content
This repository was archived by the owner on Jun 8, 2021. It is now read-only.

Conversation

@gesterhuizen
Copy link
Contributor

Add a test sub-command to the red command which runs a test and emits test metrics. Did some ad-hoc tests on k8s and it seems happy.

@gesterhuizen gesterhuizen force-pushed the ge/cmd-test branch 2 times, most recently from 1d31885 to d8eb330 Compare July 14, 2017 05:36
client.go Outdated
return DefaultClient.Query(ctx, cmd, args...)
}

type MultiError []error
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️ this!

However, should this type be unexported?

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 :)

I exported it because it's declared in package redis but used in package main.

Is there a better way to do this ?

Copy link
Contributor

Choose a reason for hiding this comment

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

The type implement the errror interface, you can change the signature of your functions to return error instead of MultiError and is should just work I think.

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 should work, but then we lose the additional errors. However, given that we don't use it anywhere (except to stringify the error), I think that's a fair compromise. We can always expose it later. Will change it.

Copy link
Contributor

@achille-roussel achille-roussel Jul 14, 2017

Choose a reason for hiding this comment

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

👍

Errors are rarely reported as concrete types in Go, instead the error interface is used. If we wanted to give access to individual errors we could expose it as an interface that the error may implement, for example something like this:

func (err multiError) Causes() []error { return ([]error)(err) }
if causes, ok := err.(interface{ Causes() []error }); ok { for _, err := range causes { // ... } }

That way we have a lose coupling between the error producer and consumer and we keep the public API short.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a nice elegant solution. I fixed this to return error now.

client.go Outdated
}

// ReadTestPattern reads a test pattern (previously writen using WriteTestPattern) from a Redis client and returns hit statistics.
func ReadTestPattern(client *Client, n int, keyTempl string, timeout time.Duration) (numHits int, numMisses int, numErrors int, err MultiError) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do these function belong to the redistest subpackage?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They're used from main as the test subcommand uses them.

So, basically, the redis library exposes functionality anyone (including us when we write red) can use to write these tests.

Happy for suggestions to make it better.

Copy link
Contributor

Choose a reason for hiding this comment

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

If you put it in the redistest subpackage it's available from everywhere else, you'd call redistest.ReadTestPattern instead of redis.ReadTestPattern ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair. Fixed.

cmd/red/test.go Outdated

for i := 0; config.Runs == 0 || i < config.Runs; i++ {
logger.Printf("Starting run #%d.", i)
transport := &redis.Transport{}
Copy link
Contributor

@achille-roussel achille-roussel Jul 14, 2017

Choose a reason for hiding this comment

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

You can decorate the transport with the redisstats.NewTransport(redis.RoundTripper) function, so your client will magically start producing more metrics ;)

Call it like this:

transport := redisstats.NewTransport(&redis.Transport{})`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fancy :) Will do that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@gesterhuizen gesterhuizen force-pushed the ge/cmd-test branch 3 times, most recently from 15c9f42 to 41ee2e4 Compare July 14, 2017 07:49
@gesterhuizen
Copy link
Contributor Author

Merging.

@gesterhuizen gesterhuizen merged commit 07f4862 into master Jul 14, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

3 participants