From 076a37cbe83a025ec06f1ced44805547a406bf72 Mon Sep 17 00:00:00 2001 From: Peter Bourgon Date: Sun, 30 May 2021 04:50:11 +0200 Subject: [PATCH] NATS update (#1095) * fix(CVE-2020-26892): 9.8 CRITICAL Updating github.com/nats-io/nats-server/v2 to version 2.2.6... Updating github.com/nats-io/nats.go to version 1.11.0... * build(deps): go mod tidy * Patch Co-authored-by: Christopher Loessl --- go.mod | 8 +- go.sum | 66 ++++++++---- transport/nats/publisher_test.go | 64 ++++++----- transport/nats/subscriber_test.go | 170 ++++++++++++++++-------------- 4 files changed, 173 insertions(+), 135 deletions(-) diff --git a/go.mod b/go.mod index e1669cafc..90091e198 100644 --- a/go.mod +++ b/go.mod @@ -21,7 +21,7 @@ require ( github.com/franela/goreq v0.0.0-20171204163338-bcd34c9993f8 // indirect github.com/go-logfmt/logfmt v0.5.0 github.com/go-stack/stack v1.8.0 - github.com/golang/protobuf v1.3.2 + github.com/golang/protobuf v1.4.2 github.com/gorilla/mux v1.7.3 github.com/hashicorp/consul/api v1.3.0 github.com/hashicorp/go-version v1.2.0 // indirect @@ -29,8 +29,8 @@ require ( github.com/hudl/fargo v1.3.0 github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d github.com/lightstep/lightstep-tracer-go v0.22.0 - github.com/nats-io/nats-server/v2 v2.1.2 - github.com/nats-io/nats.go v1.9.1 + github.com/nats-io/nats-server/v2 v2.2.6 + github.com/nats-io/nats.go v1.11.0 github.com/oklog/oklog v0.3.2 github.com/oklog/run v1.0.0 // indirect github.com/op/go-logging v0.0.0-20160315200505-970db520ece7 // indirect @@ -53,7 +53,7 @@ require ( go.opencensus.io v0.22.3 go.uber.org/zap v1.13.0 golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e - golang.org/x/time v0.0.0-20191024005414-555d28b269f0 + golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1 golang.org/x/tools v0.0.0-20200103221440-774c71fcf114 google.golang.org/grpc v1.26.0 gopkg.in/gcfg.v1 v1.2.3 // indirect diff --git a/go.sum b/go.sum index b41a5f30d..b56b1264e 100644 --- a/go.sum +++ b/go.sum @@ -103,16 +103,23 @@ github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4er github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0 h1:0udJVsspx3VBr5FwtLhQQtuAsVc79tTq0ocGIPAU6qo= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.0.0 h1:b4Gk+7WdP/d3HZH8EJsZpvV7EtDOgaZLtnaNGIu1adA= @@ -186,6 +193,8 @@ github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfV github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/klauspost/compress v1.11.12 h1:famVnQVu7QwryBN4jNseQdUKES71ZAOnB6UQQJPZvqk= +github.com/klauspost/compress v1.11.12/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= @@ -207,6 +216,8 @@ github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0j github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/miekg/dns v1.0.14 h1:9jZdLNd/P4+SfEJ0TNyxYpsK8N4GtfylBLqtbYN1sbA= github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= +github.com/minio/highwayhash v1.0.1 h1:dZ6IIu8Z14VlC0VpfKofAhCy74wu/Qb5gcn52yWoz/0= +github.com/minio/highwayhash v1.0.1/go.mod h1:BQskDq+xkJ12lmlUUi7U0M5Swg3EWR+dLTk+kldvVxY= github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= github.com/mitchellh/go-homedir v1.0.0 h1:vKb8ShqSby24Yrqr/yDYkuFz8d0WUjys40rvnGC8aR0= github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= @@ -224,16 +235,17 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lN github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= -github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg= -github.com/nats-io/jwt v0.3.2 h1:+RB5hMpXUUA2dfxuhBTEkMOrYmM+gKIZYS1KjSostMI= -github.com/nats-io/jwt v0.3.2/go.mod h1:/euKqTS1ZD+zzjYrY7pseZrTtWQSjujC7xjPc8wL6eU= -github.com/nats-io/nats-server/v2 v2.1.2 h1:i2Ly0B+1+rzNZHHWtD4ZwKi+OU5l+uQo1iDHZ2PmiIc= -github.com/nats-io/nats-server/v2 v2.1.2/go.mod h1:Afk+wRZqkMQs/p45uXdrVLuab3gwv3Z8C4HTBu8GD/k= -github.com/nats-io/nats.go v1.9.1 h1:ik3HbLhZ0YABLto7iX80pZLPw/6dx3T+++MZJwLnMrQ= -github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzEE/Zbp4w= -github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= -github.com/nats-io/nkeys v0.1.3 h1:6JrEfig+HzTH85yxzhSVbjHRJv9cn0p6n3IngIcM5/k= -github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= +github.com/nats-io/jwt v1.2.2 h1:w3GMTO969dFg+UOKTmmyuu7IGdusK+7Ytlt//OYH/uU= +github.com/nats-io/jwt v1.2.2/go.mod h1:/xX356yQA6LuXI9xWW7mZNpxgF2mBmGecH+Fj34sP5Q= +github.com/nats-io/jwt/v2 v2.0.2 h1:ejVCLO8gu6/4bOKIHQpmB5UhhUJfAQw55yvLWpfmKjI= +github.com/nats-io/jwt/v2 v2.0.2/go.mod h1:VRP+deawSXyhNjXmxPCHskrR6Mq50BqpEI5SEcNiGlY= +github.com/nats-io/nats-server/v2 v2.2.6 h1:FPK9wWx9pagxcw14s8W9rlfzfyHm61uNLnJyybZbn48= +github.com/nats-io/nats-server/v2 v2.2.6/go.mod h1:sEnFaxqe09cDmfMgACxZbziXnhQFhwk+aKkZjBBRYrI= +github.com/nats-io/nats.go v1.11.0 h1:L263PZkrmkRJRJT2YHU8GwWWvEvmr9/LUKuJTXsF32k= +github.com/nats-io/nats.go v1.11.0/go.mod h1:BPko4oXsySz4aSWeFgOHLZs3G4Jq4ZAyE6/zMCxRT6w= +github.com/nats-io/nkeys v0.2.0/go.mod h1:XdZpAbhgyyODYqjTawOnIOI7VlbKSarI9Gfy1tqEu/s= +github.com/nats-io/nkeys v0.3.0 h1:cgM5tL53EvYRU+2YLXIK0G2mJtK12Ft9oeooSZMA2G8= +github.com/nats-io/nkeys v0.3.0/go.mod h1:gvUNGjVcM2IPr5rCsRsC6Wb3Hr2CQAm08dsxtV6A5y4= github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw= github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= github.com/oklog/oklog v0.3.2 h1:wVfs8F+in6nTBMkA7CbRw+zZMIB7nNM825cM1wuzoTk= @@ -357,9 +369,10 @@ golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnf golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 h1:ObdrDkeb4kJdCP557AjRjq69pTHfNouLtWZG7j9rPN8= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20210314154223-e6e6c4f2bb5b h1:wSOdpTq0/eI46Ez/LkDwIsAKA71YP2SRKBODiRWM0as= +golang.org/x/crypto v0.0.0-20210314154223-e6e6c4f2bb5b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= @@ -381,8 +394,9 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7 h1:fHDIZ2oxGnUZRN6WgWFCbYBjH9uqVPRCUVUDhs0wnbA= golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 h1:qWPm9rbaAMKs8Bq/9LRpbMqxWRVUAQwMI9fVrssnTfw= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -398,20 +412,23 @@ golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190130150945-aca44879d564/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191220142924-d4481acd189f h1:68K/z8GLUxV76xGSqwTWw2gyk/jwn79LUL43rES2g8o= golang.org/x/sys v0.0.0-20191220142924-d4481acd189f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/time v0.0.0-20191024005414-555d28b269f0 h1:/5xXl8Y5W96D+TtHSlonuFqGHIWVuyCkGJLwGh9JJFs= -golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1 h1:NusfzzA6yGQ+ua51ck7E3omNUX/JuqbFSaRGqU8CcLI= +golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -426,6 +443,8 @@ golang.org/x/tools v0.0.0-20200103221440-774c71fcf114 h1:DnSr2mCsxyCE6ZgIkmcWUQY golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.2.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= @@ -443,6 +462,13 @@ google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyac google.golang.org/grpc v1.23.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.26.0 h1:2dTRdpdFEEhJYQD8EMLB61nnrzSCTbG38PhqdhvOltg= google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= diff --git a/transport/nats/publisher_test.go b/transport/nats/publisher_test.go index a29c76449..d5ece097a 100644 --- a/transport/nats/publisher_test.go +++ b/transport/nats/publisher_test.go @@ -19,11 +19,12 @@ func TestPublisher(t *testing.T) { } ) - nc := newNatsConn(t) - defer nc.Close() + s, c := newNATSConn(t) + defer func() { s.Shutdown(); s.WaitForShutdown() }() + defer c.Close() - sub, err := nc.QueueSubscribe("natstransport.test", "natstransport", func(msg *nats.Msg) { - if err := nc.Publish(msg.Reply, []byte(testdata)); err != nil { + sub, err := c.QueueSubscribe("natstransport.test", "natstransport", func(msg *nats.Msg) { + if err := c.Publish(msg.Reply, []byte(testdata)); err != nil { t.Fatal(err) } }) @@ -33,7 +34,7 @@ func TestPublisher(t *testing.T) { defer sub.Unsubscribe() publisher := natstransport.NewPublisher( - nc, + c, "natstransport.test", encode, decode, @@ -63,11 +64,12 @@ func TestPublisherBefore(t *testing.T) { } ) - nc := newNatsConn(t) - defer nc.Close() + s, c := newNATSConn(t) + defer func() { s.Shutdown(); s.WaitForShutdown() }() + defer c.Close() - sub, err := nc.QueueSubscribe("natstransport.test", "natstransport", func(msg *nats.Msg) { - if err := nc.Publish(msg.Reply, msg.Data); err != nil { + sub, err := c.QueueSubscribe("natstransport.test", "natstransport", func(msg *nats.Msg) { + if err := c.Publish(msg.Reply, msg.Data); err != nil { t.Fatal(err) } }) @@ -77,7 +79,7 @@ func TestPublisherBefore(t *testing.T) { defer sub.Unsubscribe() publisher := natstransport.NewPublisher( - nc, + c, "natstransport.test", encode, decode, @@ -111,11 +113,12 @@ func TestPublisherAfter(t *testing.T) { } ) - nc := newNatsConn(t) - defer nc.Close() + s, c := newNATSConn(t) + defer func() { s.Shutdown(); s.WaitForShutdown() }() + defer c.Close() - sub, err := nc.QueueSubscribe("natstransport.test", "natstransport", func(msg *nats.Msg) { - if err := nc.Publish(msg.Reply, []byte(testdata)); err != nil { + sub, err := c.QueueSubscribe("natstransport.test", "natstransport", func(msg *nats.Msg) { + if err := c.Publish(msg.Reply, []byte(testdata)); err != nil { t.Fatal(err) } }) @@ -125,7 +128,7 @@ func TestPublisherAfter(t *testing.T) { defer sub.Unsubscribe() publisher := natstransport.NewPublisher( - nc, + c, "natstransport.test", encode, decode, @@ -158,13 +161,14 @@ func TestPublisherTimeout(t *testing.T) { } ) - nc := newNatsConn(t) - defer nc.Close() + s, c := newNATSConn(t) + defer func() { s.Shutdown(); s.WaitForShutdown() }() + defer c.Close() ch := make(chan struct{}) defer close(ch) - sub, err := nc.QueueSubscribe("natstransport.test", "natstransport", func(msg *nats.Msg) { + sub, err := c.QueueSubscribe("natstransport.test", "natstransport", func(msg *nats.Msg) { <-ch }) if err != nil { @@ -173,7 +177,7 @@ func TestPublisherTimeout(t *testing.T) { defer sub.Unsubscribe() publisher := natstransport.NewPublisher( - nc, + c, "natstransport.test", encode, decode, @@ -195,11 +199,12 @@ func TestPublisherCancellation(t *testing.T) { } ) - nc := newNatsConn(t) - defer nc.Close() + s, c := newNATSConn(t) + defer func() { s.Shutdown(); s.WaitForShutdown() }() + defer c.Close() - sub, err := nc.QueueSubscribe("natstransport.test", "natstransport", func(msg *nats.Msg) { - if err := nc.Publish(msg.Reply, []byte(testdata)); err != nil { + sub, err := c.QueueSubscribe("natstransport.test", "natstransport", func(msg *nats.Msg) { + if err := c.Publish(msg.Reply, []byte(testdata)); err != nil { t.Fatal(err) } }) @@ -209,7 +214,7 @@ func TestPublisherCancellation(t *testing.T) { defer sub.Unsubscribe() publisher := natstransport.NewPublisher( - nc, + c, "natstransport.test", encode, decode, @@ -227,13 +232,14 @@ func TestPublisherCancellation(t *testing.T) { func TestEncodeJSONRequest(t *testing.T) { var data string - nc := newNatsConn(t) - defer nc.Close() + s, c := newNATSConn(t) + defer func() { s.Shutdown(); s.WaitForShutdown() }() + defer c.Close() - sub, err := nc.QueueSubscribe("natstransport.test", "natstransport", func(msg *nats.Msg) { + sub, err := c.QueueSubscribe("natstransport.test", "natstransport", func(msg *nats.Msg) { data = string(msg.Data) - if err := nc.Publish(msg.Reply, []byte("")); err != nil { + if err := c.Publish(msg.Reply, []byte("")); err != nil { t.Fatal(err) } }) @@ -243,7 +249,7 @@ func TestEncodeJSONRequest(t *testing.T) { defer sub.Unsubscribe() publisher := natstransport.NewPublisher( - nc, + c, "natstransport.test", natstransport.EncodeJSONRequest, func(context.Context, *nats.Msg) (interface{}, error) { return nil, nil }, diff --git a/transport/nats/subscriber_test.go b/transport/nats/subscriber_test.go index 69a097f1e..2b0808430 100644 --- a/transport/nats/subscriber_test.go +++ b/transport/nats/subscriber_test.go @@ -21,50 +21,49 @@ type TestResponse struct { Error string `json:"err"` } -var natsServer *server.Server - -func init() { - natsServer = server.New(&server.Options{ +func newNATSConn(t *testing.T) (*server.Server, *nats.Conn) { + s, err := server.NewServer(&server.Options{ Host: "localhost", - Port: 4222, + Port: 0, }) + if err != nil { + t.Fatal(err) + } - go func() { - natsServer.Start() - }() + go s.Start() - if ok := natsServer.ReadyForConnections(2 * time.Second); !ok { - panic("Failed start of NATS") + for i := 0; i < 5 && !s.Running(); i++ { + t.Logf("Running %v", s.Running()) + time.Sleep(time.Second) + } + if !s.Running() { + s.Shutdown() + s.WaitForShutdown() + t.Fatal("not yet running") } -} -func newNatsConn(t *testing.T) *nats.Conn { - // Subscriptions and connections are closed asynchronously, so it's possible - // that there's still a subscription from an old connection that must be closed - // before the current test can be run. - for tries := 20; tries > 0; tries-- { - if natsServer.NumSubscriptions() == 0 { - break - } + t.Log(s.Addr().String()) - time.Sleep(5 * time.Millisecond) + if ok := s.ReadyForConnections(5 * time.Second); !ok { + t.Fatal("not ready for connections") } - if n := natsServer.NumSubscriptions(); n > 0 { - t.Fatalf("found %d active subscriptions on the server", n) - } + //if n := s.NumSubscriptions(); n > 0 { + // t.Fatalf("found %d active subscriptions on the server", n) + //} - nc, err := nats.Connect("nats://"+natsServer.Addr().String(), nats.Name(t.Name())) + c, err := nats.Connect("nats://"+s.Addr().String(), nats.Name(t.Name())) if err != nil { - t.Fatalf("failed to connect to gnatsd server: %s", err) + t.Fatalf("failed to connect to NATS server: %s", err) } - return nc + return s, c } func TestSubscriberBadDecode(t *testing.T) { - nc := newNatsConn(t) - defer nc.Close() + s, c := newNATSConn(t) + defer func() { s.Shutdown(); s.WaitForShutdown() }() + defer c.Close() handler := natstransport.NewSubscriber( func(context.Context, interface{}) (interface{}, error) { return struct{}{}, nil }, @@ -72,7 +71,7 @@ func TestSubscriberBadDecode(t *testing.T) { func(context.Context, string, *nats.Conn, interface{}) error { return nil }, ) - resp := testRequest(t, nc, handler) + resp := testRequest(t, c, handler) if want, have := "dang", resp.Error; want != have { t.Errorf("want %s, have %s", want, have) @@ -81,8 +80,9 @@ func TestSubscriberBadDecode(t *testing.T) { } func TestSubscriberBadEndpoint(t *testing.T) { - nc := newNatsConn(t) - defer nc.Close() + s, c := newNATSConn(t) + defer func() { s.Shutdown(); s.WaitForShutdown() }() + defer c.Close() handler := natstransport.NewSubscriber( func(context.Context, interface{}) (interface{}, error) { return struct{}{}, errors.New("dang") }, @@ -90,7 +90,7 @@ func TestSubscriberBadEndpoint(t *testing.T) { func(context.Context, string, *nats.Conn, interface{}) error { return nil }, ) - resp := testRequest(t, nc, handler) + resp := testRequest(t, c, handler) if want, have := "dang", resp.Error; want != have { t.Errorf("want %s, have %s", want, have) @@ -98,8 +98,9 @@ func TestSubscriberBadEndpoint(t *testing.T) { } func TestSubscriberBadEncode(t *testing.T) { - nc := newNatsConn(t) - defer nc.Close() + s, c := newNATSConn(t) + defer func() { s.Shutdown(); s.WaitForShutdown() }() + defer c.Close() handler := natstransport.NewSubscriber( func(context.Context, interface{}) (interface{}, error) { return struct{}{}, nil }, @@ -107,7 +108,7 @@ func TestSubscriberBadEncode(t *testing.T) { func(context.Context, string, *nats.Conn, interface{}) error { return errors.New("dang") }, ) - resp := testRequest(t, nc, handler) + resp := testRequest(t, c, handler) if want, have := "dang", resp.Error; want != have { t.Errorf("want %s, have %s", want, have) @@ -115,8 +116,9 @@ func TestSubscriberBadEncode(t *testing.T) { } func TestSubscriberErrorEncoder(t *testing.T) { - nc := newNatsConn(t) - defer nc.Close() + s, c := newNATSConn(t) + defer func() { s.Shutdown(); s.WaitForShutdown() }() + defer c.Close() errTeapot := errors.New("teapot") code := func(err error) error { @@ -138,13 +140,13 @@ func TestSubscriberErrorEncoder(t *testing.T) { t.Fatal(err) } - if err := nc.Publish(reply, b); err != nil { + if err := c.Publish(reply, b); err != nil { t.Fatal(err) } }), ) - resp := testRequest(t, nc, handler) + resp := testRequest(t, c, handler) if want, have := errTeapot.Error(), resp.Error; want != have { t.Errorf("want %s, have %s", want, have) @@ -168,8 +170,9 @@ func TestSubscriberHappySubject(t *testing.T) { } func TestMultipleSubscriberBefore(t *testing.T) { - nc := newNatsConn(t) - defer nc.Close() + s, c := newNATSConn(t) + defer func() { s.Shutdown(); s.WaitForShutdown() }() + defer c.Close() var ( response = struct{ Body string }{"go eat a fly ugly\n"} @@ -187,7 +190,7 @@ func TestMultipleSubscriberBefore(t *testing.T) { return err } - return nc.Publish(reply, b) + return c.Publish(reply, b) }, natstransport.SubscriberBefore(func(ctx context.Context, _ *nats.Msg) context.Context { ctx = context.WithValue(ctx, "one", 1) @@ -204,7 +207,7 @@ func TestMultipleSubscriberBefore(t *testing.T) { }), ) - sub, err := nc.QueueSubscribe("natstransport.test", "natstransport", handler.ServeMsg(nc)) + sub, err := c.QueueSubscribe("natstransport.test", "natstransport", handler.ServeMsg(c)) if err != nil { t.Fatal(err) } @@ -213,7 +216,7 @@ func TestMultipleSubscriberBefore(t *testing.T) { wg.Add(1) go func() { defer wg.Done() - _, err := nc.Request("natstransport.test", []byte("test data"), 2*time.Second) + _, err := c.Request("natstransport.test", []byte("test data"), 2*time.Second) if err != nil { t.Fatal(err) } @@ -229,8 +232,9 @@ func TestMultipleSubscriberBefore(t *testing.T) { } func TestMultipleSubscriberAfter(t *testing.T) { - nc := newNatsConn(t) - defer nc.Close() + s, c := newNATSConn(t) + defer func() { s.Shutdown(); s.WaitForShutdown() }() + defer c.Close() var ( response = struct{ Body string }{"go eat a fly ugly\n"} @@ -247,25 +251,21 @@ func TestMultipleSubscriberAfter(t *testing.T) { if err != nil { return err } - - return nc.Publish(reply, b) + return c.Publish(reply, b) }, natstransport.SubscriberAfter(func(ctx context.Context, nc *nats.Conn) context.Context { - ctx = context.WithValue(ctx, "one", 1) - - return ctx + return context.WithValue(ctx, "one", 1) }), natstransport.SubscriberAfter(func(ctx context.Context, nc *nats.Conn) context.Context { if _, ok := ctx.Value("one").(int); !ok { t.Error("Value was not set properly when multiple ServerAfters are used") } - close(done) return ctx }), ) - sub, err := nc.QueueSubscribe("natstransport.test", "natstransport", handler.ServeMsg(nc)) + sub, err := c.QueueSubscribe("natstransport.test", "natstransport", handler.ServeMsg(c)) if err != nil { t.Fatal(err) } @@ -274,7 +274,7 @@ func TestMultipleSubscriberAfter(t *testing.T) { wg.Add(1) go func() { defer wg.Done() - _, err := nc.Request("natstransport.test", []byte("test data"), 2*time.Second) + _, err := c.Request("natstransport.test", []byte("test data"), 2*time.Second) if err != nil { t.Fatal(err) } @@ -290,8 +290,9 @@ func TestMultipleSubscriberAfter(t *testing.T) { } func TestSubscriberFinalizerFunc(t *testing.T) { - nc := newNatsConn(t) - defer nc.Close() + s, c := newNATSConn(t) + defer func() { s.Shutdown(); s.WaitForShutdown() }() + defer c.Close() var ( response = struct{ Body string }{"go eat a fly ugly\n"} @@ -309,14 +310,14 @@ func TestSubscriberFinalizerFunc(t *testing.T) { return err } - return nc.Publish(reply, b) + return c.Publish(reply, b) }, natstransport.SubscriberFinalizer(func(ctx context.Context, _ *nats.Msg) { close(done) }), ) - sub, err := nc.QueueSubscribe("natstransport.test", "natstransport", handler.ServeMsg(nc)) + sub, err := c.QueueSubscribe("natstransport.test", "natstransport", handler.ServeMsg(c)) if err != nil { t.Fatal(err) } @@ -325,7 +326,7 @@ func TestSubscriberFinalizerFunc(t *testing.T) { wg.Add(1) go func() { defer wg.Done() - _, err := nc.Request("natstransport.test", []byte("test data"), 2*time.Second) + _, err := c.Request("natstransport.test", []byte("test data"), 2*time.Second) if err != nil { t.Fatal(err) } @@ -341,8 +342,9 @@ func TestSubscriberFinalizerFunc(t *testing.T) { } func TestEncodeJSONResponse(t *testing.T) { - nc := newNatsConn(t) - defer nc.Close() + s, c := newNATSConn(t) + defer func() { s.Shutdown(); s.WaitForShutdown() }() + defer c.Close() handler := natstransport.NewSubscriber( func(context.Context, interface{}) (interface{}, error) { @@ -354,13 +356,13 @@ func TestEncodeJSONResponse(t *testing.T) { natstransport.EncodeJSONResponse, ) - sub, err := nc.QueueSubscribe("natstransport.test", "natstransport", handler.ServeMsg(nc)) + sub, err := c.QueueSubscribe("natstransport.test", "natstransport", handler.ServeMsg(c)) if err != nil { t.Fatal(err) } defer sub.Unsubscribe() - r, err := nc.Request("natstransport.test", []byte("test data"), 2*time.Second) + r, err := c.Request("natstransport.test", []byte("test data"), 2*time.Second) if err != nil { t.Fatal(err) } @@ -379,8 +381,9 @@ func (m responseError) Error() string { } func TestErrorEncoder(t *testing.T) { - nc := newNatsConn(t) - defer nc.Close() + s, c := newNATSConn(t) + defer func() { s.Shutdown(); s.WaitForShutdown() }() + defer c.Close() errResp := struct { Error string `json:"err"` @@ -393,13 +396,13 @@ func TestErrorEncoder(t *testing.T) { natstransport.EncodeJSONResponse, ) - sub, err := nc.QueueSubscribe("natstransport.test", "natstransport", handler.ServeMsg(nc)) + sub, err := c.QueueSubscribe("natstransport.test", "natstransport", handler.ServeMsg(c)) if err != nil { t.Fatal(err) } defer sub.Unsubscribe() - r, err := nc.Request("natstransport.test", []byte("test data"), 2*time.Second) + r, err := c.Request("natstransport.test", []byte("test data"), 2*time.Second) if err != nil { t.Fatal(err) } @@ -416,8 +419,9 @@ func TestErrorEncoder(t *testing.T) { type noContentResponse struct{} func TestEncodeNoContent(t *testing.T) { - nc := newNatsConn(t) - defer nc.Close() + s, c := newNATSConn(t) + defer func() { s.Shutdown(); s.WaitForShutdown() }() + defer c.Close() handler := natstransport.NewSubscriber( func(context.Context, interface{}) (interface{}, error) { return noContentResponse{}, nil }, @@ -425,13 +429,13 @@ func TestEncodeNoContent(t *testing.T) { natstransport.EncodeJSONResponse, ) - sub, err := nc.QueueSubscribe("natstransport.test", "natstransport", handler.ServeMsg(nc)) + sub, err := c.QueueSubscribe("natstransport.test", "natstransport", handler.ServeMsg(c)) if err != nil { t.Fatal(err) } defer sub.Unsubscribe() - r, err := nc.Request("natstransport.test", []byte("test data"), 2*time.Second) + r, err := c.Request("natstransport.test", []byte("test data"), 2*time.Second) if err != nil { t.Fatal(err) } @@ -442,8 +446,9 @@ func TestEncodeNoContent(t *testing.T) { } func TestNoOpRequestDecoder(t *testing.T) { - nc := newNatsConn(t) - defer nc.Close() + s, c := newNATSConn(t) + defer func() { s.Shutdown(); s.WaitForShutdown() }() + defer c.Close() handler := natstransport.NewSubscriber( func(ctx context.Context, request interface{}) (interface{}, error) { @@ -456,13 +461,13 @@ func TestNoOpRequestDecoder(t *testing.T) { natstransport.EncodeJSONResponse, ) - sub, err := nc.QueueSubscribe("natstransport.test", "natstransport", handler.ServeMsg(nc)) + sub, err := c.QueueSubscribe("natstransport.test", "natstransport", handler.ServeMsg(c)) if err != nil { t.Fatal(err) } defer sub.Unsubscribe() - r, err := nc.Request("natstransport.test", []byte("test data"), 2*time.Second) + r, err := c.Request("natstransport.test", []byte("test data"), 2*time.Second) if err != nil { t.Fatal(err) } @@ -490,16 +495,17 @@ func testSubscriber(t *testing.T) (step func(), resp <-chan *nats.Msg) { ) go func() { - nc := newNatsConn(t) - defer nc.Close() + s, c := newNATSConn(t) + defer func() { s.Shutdown(); s.WaitForShutdown() }() + defer c.Close() - sub, err := nc.QueueSubscribe("natstransport.test", "natstransport", handler.ServeMsg(nc)) + sub, err := c.QueueSubscribe("natstransport.test", "natstransport", handler.ServeMsg(c)) if err != nil { t.Fatal(err) } defer sub.Unsubscribe() - r, err := nc.Request("natstransport.test", []byte("test data"), 2*time.Second) + r, err := c.Request("natstransport.test", []byte("test data"), 2*time.Second) if err != nil { t.Fatal(err) } @@ -510,14 +516,14 @@ func testSubscriber(t *testing.T) (step func(), resp <-chan *nats.Msg) { return func() { stepch <- true }, response } -func testRequest(t *testing.T, nc *nats.Conn, handler *natstransport.Subscriber) TestResponse { - sub, err := nc.QueueSubscribe("natstransport.test", "natstransport", handler.ServeMsg(nc)) +func testRequest(t *testing.T, c *nats.Conn, handler *natstransport.Subscriber) TestResponse { + sub, err := c.QueueSubscribe("natstransport.test", "natstransport", handler.ServeMsg(c)) if err != nil { t.Fatal(err) } defer sub.Unsubscribe() - r, err := nc.Request("natstransport.test", []byte("test data"), 2*time.Second) + r, err := c.Request("natstransport.test", []byte("test data"), 2*time.Second) if err != nil { t.Fatal(err) }