Commit Graph

99 Commits

Author SHA1 Message Date
Frank Schroeder c94751ad43 test: replace porter tool with freeport lib
This patch removes the porter tool which hands out free ports from a
given range with a library which does the same thing. The challenge for
acquiring free ports in concurrent go test runs is that go packages are
tested concurrently and run in separate processes. There has to be some
inter-process synchronization in preventing processes allocating the
same ports.

freeport allocates blocks of ports from a range expected to be not in
heavy use and implements a system-wide mutex by binding to the first
port of that block for the lifetime of the application. Ports are then
provided sequentially from that block and are tested on localhost before
being returned as available.
2017-10-21 22:01:09 +02:00
James Phillips ad9425ca63
Adds a canary test to fail Consul's test w/o porter. 2017-10-20 17:05:25 -07:00
Alex Dadgar c7a65b4587 Testutil falls back to random ports w/o porter (#3604)
* Testutil falls back to random ports w/o porter

This PR allows the testutil server to be used without porter.

* Adds sterner-sounding fallback comments.
2017-10-20 16:46:13 -07:00
Frank Schröder 1e461110e6 agent: consolidate handling of 405 Method Not Allowed (#3405)
* agent: consolidate http method not allowed checks

This patch uses the error handling of the http handlers to handle HTTP
method not allowed errors across all available endpoints. It also adds a
test for testing whether the endpoints respond with the correct status
code.

* agent: do not panic on metrics tests

* agent: drop other tests for MethodNotAllowed

* agent: align /agent/join with reality

/agent/join uses PUT instead of GET as documented.

* agent: align /agent/check/{fail,warn,pass} with reality

/agent/check/{fail,warn,pass} uses PUT instead of GET as documented.

* fix some tests

* Drop more tests for method not allowed

* Align TestAgent_RegisterService_InvalidAddress with reality

* Changes API client join to use PUT instead of GET.

* Fixes agent endpoint verbs and removes obsolete tests.

* Updates the change log.
2017-09-25 23:11:19 -07:00
Frank Schröder 12216583a1 New config parser, HCL support, multiple bind addrs (#3480)
* new config parser for agent

This patch implements a new config parser for the consul agent which
makes the following changes to the previous implementation:

 * add HCL support
 * all configuration fragments in tests and for default config are
   expressed as HCL fragments
 * HCL fragments can be provided on the command line so that they
   can eventually replace the command line flags.
 * HCL/JSON fragments are parsed into a temporary Config structure
   which can be merged using reflection (all values are pointers).
   The existing merge logic of overwrite for values and append
   for slices has been preserved.
 * A single builder process generates a typed runtime configuration
   for the agent.

The new implementation is more strict and fails in the builder process
if no valid runtime configuration can be generated. Therefore,
additional validations in other parts of the code should be removed.

The builder also pre-computes all required network addresses so that no
address/port magic should be required where the configuration is used
and should therefore be removed.

* Upgrade github.com/hashicorp/hcl to support int64

* improve error messages

* fix directory permission test

* Fix rtt test

* Fix ForceLeave test

* Skip performance test for now until we know what to do

* Update github.com/hashicorp/memberlist to update log prefix

* Make memberlist use the default logger

* improve config error handling

* do not fail on non-existing data-dir

* experiment with non-uniform timeouts to get a handle on stalled leader elections

* Run tests for packages separately to eliminate the spurious port conflicts

* refactor private address detection and unify approach for ipv4 and ipv6.

Fixes #2825

* do not allow unix sockets for DNS

* improve bind and advertise addr error handling

* go through builder using test coverage

* minimal update to the docs

* more coverage tests fixed

* more tests

* fix makefile

* cleanup

* fix port conflicts with external port server 'porter'

* stop test server on error

* do not run api test that change global ENV concurrently with the other tests

* Run remaining api tests concurrently

* no need for retry with the port number service

* monkey patch race condition in go-sockaddr until we understand why that fails

* monkey patch hcl decoder race condidtion until we understand why that fails

* monkey patch spurious errors in strings.EqualFold from here

* add test for hcl decoder race condition. Run with go test -parallel 128

* Increase timeout again

* cleanup

* don't log port allocations by default

* use base command arg parsing to format help output properly

* handle -dc deprecation case in Build

* switch autopilot.max_trailing_logs to int

* remove duplicate test case

* remove unused methods

* remove comments about flag/config value inconsistencies

* switch got and want around since the error message was misleading.

* Removes a stray debug log.

* Removes a stray newline in imports.

* Fixes TestACL_Version8.

* Runs go fmt.

* Adds a default case for unknown address types.

* Reoders and reformats some imports.

* Adds some comments and fixes typos.

* Reorders imports.

* add unix socket support for dns later

* drop all deprecated flags and arguments

* fix wrong field name

* remove stray node-id file

* drop unnecessary patch section in test

* drop duplicate test

* add test for LeaveOnTerm and SkipLeaveOnInt in client mode

* drop "bla" and add clarifying comment for the test

* split up tests to support enterprise/non-enterprise tests

* drop raft multiplier and derive values during build phase

* sanitize runtime config reflectively and add test

* detect invalid config fields

* fix tests with invalid config fields

* use different values for wan sanitiziation test

* drop recursor in favor of recursors

* allow dns_config.udp_answer_limit to be zero

* make sure tests run on machines with multiple ips

* Fix failing tests in a few more places by providing a bind address in the test

* Gets rid of skipped TestAgent_CheckPerformanceSettings and adds case for builder.

* Add porter to server_test.go to make tests there less flaky

* go fmt
2017-09-25 11:40:42 -07:00
James Phillips b1a15e0c3d
Adds open source side of network segments (feature is Enterprise-only). 2017-08-30 11:58:29 -07:00
James Phillips 1791d99a10 Adds new config to make script checks opt-in, updates documentation. (#3284) 2017-07-17 11:20:35 -07:00
Frank Schroeder cd0b0b35c9 api: do not block in waitForLeader since the retry loop is handling this 2017-07-07 09:22:34 +02:00
James Phillips ebe032a75c Adds a temporary band-aid to the API tests.
Once we can run the agent directly in-process with random ports from the kernel,
and the special retry just in memberlist, we shouldn't need this.
2017-07-07 09:22:34 +02:00
Frank Schroeder 3aa752e998 retry: relax timing for test a bit 2017-07-07 09:22:34 +02:00
Frank Schroeder 1d5b56eec1
test: shutdown server properly 2017-05-31 00:29:22 +02:00
Frank Schroeder eded493206
test: sanitize temp dir names since subtest names have slashes 2017-05-31 00:29:22 +02:00
Frank Schroeder 4edd1dcba2 test: fix go vet issue 2017-05-12 22:12:47 +02:00
Frank Schroeder f44c4e769b test: bump ReadyTimeout to 10s 2017-05-12 22:12:47 +02:00
Frank Schroeder 65b5c51ec7 test: add helper for ioutil.TempDir/TempFile
This creates a simplified helper for temporary directories and files.
All path names are prefixed with the name of the current test.
All files and directories are stored either in /tmp/consul-test
or /tmp if the former could not be created.

Using the system temp dir breaks some tests on macOS where the unix
socket path becomes too long.
2017-05-12 22:12:47 +02:00
Frank Schroeder 3522a41bad test: include test name in temp file/dir
This helps identifying hanging tests by looking
at the process list.
2017-05-12 22:12:47 +02:00
Cyril Gaudin 417ffb8893 test: Make testserver start timeout configurable. 2017-05-09 17:48:53 +02:00
James Phillips 33a7b8e401
Tweaks some tests that were having a hard time in Travis CI and
bumps up the default retry time.
2017-05-09 06:48:26 -07:00
Frank Schroeder 7732347172
test: simplify tests that check for peers 2017-05-05 17:07:04 +02:00
Frank Schroeder c3d6814149
test: Drop WaitForResult from testutil and testrpc 2017-05-05 17:07:03 +02:00
James Phillips ddfa57765c
retry: Removes the description parameter. 2017-05-05 17:07:03 +02:00
Frank Schroeder eb6465551b
retry: add retry package for retriable tests
The current retry framework in testutil/testprc.WaitForResult uses
a func() (bool, error) callback until it succeeds or times out.
It captures the last error and returns it.

    if err := testutil.WaitForResult(t, func() (bool, error) {
	if err := foo(); err != nil {
	    return false, err
	}
	...
	return true, nil
    }); err != nil {
	t.Fatal(err)
    }

This makes the test functions more complex than they need to be since
both the boolean and the error indicate a success or a failure.

The retry.Run framework uses a an approach similar to t.Run()
from the testing framework.

    retry.Run(t, func(r *retry.R) {
	if err := foo(); err != nil {
	    r.Fatal(err)
	}
    })

The behavior of the Run function is configurable so that different
timeouts can be used for different tests.
2017-05-05 17:07:02 +02:00
Ethan Chu 90fe8b3418
Add `AddAccessibleService` to testutil
`AddAccessibleService` works just like `AddService` but also passing
"address" and "port". It is helpfu when you need to prepare a
fakeService that will be accessed later in target source code.
2017-05-01 13:56:48 -07:00
Kyle Havlovitz cd56a5ebdd Add separate option for verifying incoming HTTPS traffic (#2974)
* Add separate option for verifying incoming HTTPS traffic
2017-04-28 16:15:55 -07:00
Frank Schroeder 80c990b449 test: Retry more aggressively 2017-04-27 10:34:30 -07:00
Frank Schroeder 3403cd4372 golint: Fix existing comments
This needs more work.
2017-04-25 09:26:13 -07:00
Frank Schroeder 3e00e36f41 golint: Untangle if blocks with return in else 2017-04-25 09:26:13 -07:00
Frank Schroeder cf3ec1cf5c golint: Rename fields and structs 2017-04-25 09:26:13 -07:00
Frank Schroeder eddb1af603 Remove duplicate constants
This patch removes duplicate internal copies of constants in the structs
package which are also defined in the api package. The api.KVOp type
with all its values for the TXN endpoint and the api.HealthXXX constants
are now used throughout the codebase.

This resulted in some circular dependencies in the testutil package
which have been resolved by copying code and constants and moving the
WaitForLeader function into a separate testrpc package.
2017-04-20 09:54:49 -07:00
Kyle Havlovitz ae6bf56ee1
Add tls client options to api/cli 2017-04-14 13:37:29 -07:00
James Phillips 59a599a14b
Cleans up a stray mark and fixes unit tests.
Ended up removing the leader_test.go server address change test as part
of this. The join was failing becase we were using a new node name with
the new logic here, but realized this was hitting some of the memberlist
conflict logic and not working as we expected. We need some additional
work to fully support address changes, so removed the test for now.
2017-03-27 01:28:54 -07:00
James Phillips 4d3f3ea8d2
Changes verson 8 ACLs to opt-out. 2017-03-24 12:12:24 -07:00
James Phillips 15e7247131
Fixes test server startup returning wrong error.
Seen in https://travis-ci.org/hashicorp/consul/builds/214521317.
2017-03-23 21:40:14 -07:00
James Phillips 4e7064023f
Makes WaitForResult always return an error if it times out. 2017-03-23 20:04:39 -07:00
Seth Vargo 1dc1f72fb6
Add RPC 2017-03-23 18:41:20 -04:00
Seth Vargo 3d830b3676
Reduce coupling with testing.T
This reduces the coupling with testing.T, allowing many of the
server's startup-related functions to return an error. This makes them
more re-usable.
2017-03-23 18:41:19 -04:00
Kyle Havlovitz 9b4497de09
Cleaned up and reorganized some autopilot-related code 2017-03-09 18:21:40 -08:00
Kyle Havlovitz f389b59fd5
Fix up command and api tests 2017-02-28 14:12:55 -08:00
Jeff Mitchell 44733caf5c Update unix dial functions to use DialContext with new go-cleanhttp 2017-02-10 21:11:21 -05:00
James Phillips 14c6d009cc Drop testutil wait to 2 seconds.
There's likely a race (related to https://github.com/hashicorp/consul/issues/2644) where the catalog update might be in but the leader tracking doesn't report a leader, so this blocks forever and then times out. As a workaround we can lower the query wait time to always allow for a few retries.
2017-02-06 11:52:00 -08:00
James Phillips dcff5137f9
Adds a little wait after we get the event we were seeking. 2017-01-26 22:15:54 -08:00
James Phillips 8493d239ac
Run the waited-for function before sleeping, and ramp up the sleep exponentially. 2017-01-26 17:11:16 -08:00
James Phillips 8c33ddbee2
Drops the unit test wait time back down and turns initial wait into blocking query. 2017-01-26 16:57:44 -08:00
James Phillips 1f903547b5 Bumps the wait even more. 2017-01-26 09:15:29 -08:00
James Phillips 86368a467e Bumps the wait a little more. 2017-01-26 08:20:43 -08:00
James Phillips b4bbd2f441 Adds more time to WaitForResult.
The last change here made the time overall theoretically the same, but the overhead of running so quickly before probably meant that we were spending longer. Tests seemed marginal in Travis so doubling this to see how things go.
2017-01-26 08:04:48 -08:00
Seth Vargo e3a4b2128b
Sleep for longer, but try less often
This fixes an issue where the system can quickly run out of file
descriptors because they are accumulating faster than the kernel can
release them.
2017-01-26 00:13:34 -05:00
Seth Vargo c0b6c7ad3e
Check to see if TaggedAddresses have been populated
This ensures the node's anti-entropy checks have finished before
telling the client Consul is ready.
2017-01-26 00:13:03 -05:00
Seth Vargo 624b7daba4 Omit empty node_meta 2017-01-17 20:17:20 -05:00
Kyle Havlovitz f48f105949
Minor formatting tweaks as a follow-up to #2654 2017-01-17 19:20:29 -05:00