mirror of
https://github.com/openfaas/faas.git
synced 2025-06-19 20:46:41 +00:00
Vendor new queue-worker version
Introduces 0.4.6 of queue-worker - see upstream repo for changes. Signed-off-by: Alex Ellis (VMware) <alexellis2@gmail.com>
This commit is contained in:
127
gateway/vendor/github.com/nats-io/go-nats/nats_test.go
generated
vendored
127
gateway/vendor/github.com/nats-io/go-nats/nats_test.go
generated
vendored
@ -1,3 +1,16 @@
|
||||
// Copyright 2012-2018 The NATS Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package nats
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@ -10,6 +23,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"strings"
|
||||
@ -40,7 +54,7 @@ func stackFatalf(t *testing.T, f string, args ...interface{}) {
|
||||
lines = append(lines, msg)
|
||||
|
||||
// Generate the Stack of callers: Skip us and verify* frames.
|
||||
for i := 2; true; i++ {
|
||||
for i := 1; true; i++ {
|
||||
_, file, line, ok := runtime.Caller(i)
|
||||
if !ok {
|
||||
break
|
||||
@ -51,6 +65,23 @@ func stackFatalf(t *testing.T, f string, args ...interface{}) {
|
||||
t.Fatalf("%s", strings.Join(lines, "\n"))
|
||||
}
|
||||
|
||||
func TestVersionMatchesTag(t *testing.T) {
|
||||
tag := os.Getenv("TRAVIS_TAG")
|
||||
if tag == "" {
|
||||
t.SkipNow()
|
||||
}
|
||||
// We expect a tag of the form vX.Y.Z. If that's not the case,
|
||||
// we need someone to have a look. So fail if first letter is not
|
||||
// a `v`
|
||||
if tag[0] != 'v' {
|
||||
t.Fatalf("Expect tag to start with `v`, tag is: %s", tag)
|
||||
}
|
||||
// Strip the `v` from the tag for the version comparison.
|
||||
if Version != tag[1:] {
|
||||
t.Fatalf("Version (%s) does not match tag (%s)", Version, tag[1:])
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Reconnect tests
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@ -935,7 +966,7 @@ func TestAsyncINFO(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
checkPool := func(inThatOrder bool, urls ...string) {
|
||||
checkPool := func(urls ...string) {
|
||||
// Check both pool and urls map
|
||||
if len(c.srvPool) != len(urls) {
|
||||
stackFatalf(t, "Pool should have %d elements, has %d", len(urls), len(c.srvPool))
|
||||
@ -943,35 +974,27 @@ func TestAsyncINFO(t *testing.T) {
|
||||
if len(c.urls) != len(urls) {
|
||||
stackFatalf(t, "Map should have %d elements, has %d", len(urls), len(c.urls))
|
||||
}
|
||||
for i, url := range urls {
|
||||
if inThatOrder {
|
||||
if c.srvPool[i].url.Host != url {
|
||||
stackFatalf(t, "Pool should have %q at index %q, has %q", url, i, c.srvPool[i].url.Host)
|
||||
}
|
||||
} else {
|
||||
if _, present := c.urls[url]; !present {
|
||||
stackFatalf(t, "Pool should have %q", url)
|
||||
}
|
||||
for _, url := range urls {
|
||||
if _, present := c.urls[url]; !present {
|
||||
stackFatalf(t, "Pool should have %q", url)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Now test the decoding of "connect_urls"
|
||||
|
||||
// No randomize for now
|
||||
c.Opts.NoRandomize = true
|
||||
// Reset the pool
|
||||
c.setupServerPool()
|
||||
// Reinitialize the parser
|
||||
c.ps = &parseState{}
|
||||
|
||||
info = []byte("INFO {\"connect_urls\":[\"localhost:5222\"]}\r\n")
|
||||
info = []byte("INFO {\"connect_urls\":[\"localhost:4222\", \"localhost:5222\"]}\r\n")
|
||||
err = c.parse(info)
|
||||
if err != nil || c.ps.state != OP_START {
|
||||
t.Fatalf("Unexpected: %d : %v\n", c.ps.state, err)
|
||||
}
|
||||
// Pool now should contain localhost:4222 (the default URL) and localhost:5222
|
||||
checkPool(true, "localhost:4222", "localhost:5222")
|
||||
checkPool("localhost:4222", "localhost:5222")
|
||||
|
||||
// Make sure that if client receives the same, it is not added again.
|
||||
err = c.parse(info)
|
||||
@ -979,84 +1002,16 @@ func TestAsyncINFO(t *testing.T) {
|
||||
t.Fatalf("Unexpected: %d : %v\n", c.ps.state, err)
|
||||
}
|
||||
// Pool should still contain localhost:4222 (the default URL) and localhost:5222
|
||||
checkPool(true, "localhost:4222", "localhost:5222")
|
||||
checkPool("localhost:4222", "localhost:5222")
|
||||
|
||||
// Receive a new URL
|
||||
info = []byte("INFO {\"connect_urls\":[\"localhost:6222\"]}\r\n")
|
||||
info = []byte("INFO {\"connect_urls\":[\"localhost:4222\", \"localhost:5222\", \"localhost:6222\"]}\r\n")
|
||||
err = c.parse(info)
|
||||
if err != nil || c.ps.state != OP_START {
|
||||
t.Fatalf("Unexpected: %d : %v\n", c.ps.state, err)
|
||||
}
|
||||
// Pool now should contain localhost:4222 (the default URL) localhost:5222 and localhost:6222
|
||||
checkPool(true, "localhost:4222", "localhost:5222", "localhost:6222")
|
||||
|
||||
// Receive more than 1 URL at once
|
||||
info = []byte("INFO {\"connect_urls\":[\"localhost:7222\", \"localhost:8222\"]}\r\n")
|
||||
err = c.parse(info)
|
||||
if err != nil || c.ps.state != OP_START {
|
||||
t.Fatalf("Unexpected: %d : %v\n", c.ps.state, err)
|
||||
}
|
||||
// Pool now should contain localhost:4222 (the default URL) localhost:5222, localhost:6222
|
||||
// localhost:7222 and localhost:8222
|
||||
checkPool(true, "localhost:4222", "localhost:5222", "localhost:6222", "localhost:7222", "localhost:8222")
|
||||
|
||||
// Test with pool randomization now. Note that with randominzation,
|
||||
// the initial pool is randomize, then each array of urls that the
|
||||
// client gets from the INFO protocol is randomized, but added to
|
||||
// the end of the pool.
|
||||
c.Opts.NoRandomize = false
|
||||
c.setupServerPool()
|
||||
|
||||
info = []byte("INFO {\"connect_urls\":[\"localhost:5222\"]}\r\n")
|
||||
err = c.parse(info)
|
||||
if err != nil || c.ps.state != OP_START {
|
||||
t.Fatalf("Unexpected: %d : %v\n", c.ps.state, err)
|
||||
}
|
||||
// Pool now should contain localhost:4222 (the default URL) and localhost:5222
|
||||
checkPool(true, "localhost:4222", "localhost:5222")
|
||||
|
||||
// Make sure that if client receives the same, it is not added again.
|
||||
err = c.parse(info)
|
||||
if err != nil || c.ps.state != OP_START {
|
||||
t.Fatalf("Unexpected: %d : %v\n", c.ps.state, err)
|
||||
}
|
||||
// Pool should still contain localhost:4222 (the default URL) and localhost:5222
|
||||
checkPool(true, "localhost:4222", "localhost:5222")
|
||||
|
||||
// Receive a new URL
|
||||
info = []byte("INFO {\"connect_urls\":[\"localhost:6222\"]}\r\n")
|
||||
err = c.parse(info)
|
||||
if err != nil || c.ps.state != OP_START {
|
||||
t.Fatalf("Unexpected: %d : %v\n", c.ps.state, err)
|
||||
}
|
||||
// Pool now should contain localhost:4222 (the default URL) localhost:5222 and localhost:6222
|
||||
checkPool(true, "localhost:4222", "localhost:5222", "localhost:6222")
|
||||
|
||||
// Receive more than 1 URL at once. Add more than 2 to increase the chance of
|
||||
// the array being shuffled.
|
||||
info = []byte("INFO {\"connect_urls\":[\"localhost:7222\", \"localhost:8222\", " +
|
||||
"\"localhost:9222\", \"localhost:10222\", \"localhost:11222\"]}\r\n")
|
||||
err = c.parse(info)
|
||||
if err != nil || c.ps.state != OP_START {
|
||||
t.Fatalf("Unexpected: %d : %v\n", c.ps.state, err)
|
||||
}
|
||||
// Pool now should contain localhost:4222 (the default URL) localhost:5222, localhost:6222
|
||||
// localhost:7222, localhost:8222, localhost:9222, localhost:10222 and localhost:11222
|
||||
checkPool(false, "localhost:4222", "localhost:5222", "localhost:6222", "localhost:7222", "localhost:8222",
|
||||
"localhost:9222", "localhost:10222", "localhost:11222")
|
||||
|
||||
// Finally, check that (part of) the pool should be randomized.
|
||||
allUrls := []string{"localhost:4222", "localhost:5222", "localhost:6222", "localhost:7222", "localhost:8222",
|
||||
"localhost:9222", "localhost:10222", "localhost:11222"}
|
||||
same := 0
|
||||
for i, url := range c.srvPool {
|
||||
if url.url.Host == allUrls[i] {
|
||||
same++
|
||||
}
|
||||
}
|
||||
if same == len(allUrls) {
|
||||
t.Fatal("Pool does not seem to be randomized")
|
||||
}
|
||||
checkPool("localhost:4222", "localhost:5222", "localhost:6222")
|
||||
|
||||
// Check that pool may be randomized on setup, but new URLs are always
|
||||
// added at end of pool.
|
||||
|
Reference in New Issue
Block a user