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

Pass build tags to unit tests #2618

Merged
merged 5 commits into from
Jul 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ shell: $(SCOPE_BACKEND_BUILD_UPTODATE)
/bin/bash

tests: $(SCOPE_BACKEND_BUILD_UPTODATE) $(CODECGEN_TARGETS) prog/staticui/staticui.go prog/externalui/externalui.go
./tools/test -no-go-get
./tools/test -no-go-get -tags $(GO_BUILD_TAGS)

lint: $(SCOPE_BACKEND_BUILD_UPTODATE)
./tools/lint
Expand Down
5 changes: 3 additions & 2 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
FROM ubuntu:yakkety
ENV GOPATH /go
ENV GOVERSION 1.8.3
ENV PATH /go/bin:/usr/local/go/bin:/usr/bin:/bin:/usr/sbin:/sbin
ENV PATH /go/bin:/usr/local/go/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
ENV SCOPE_SKIP_UI_ASSETS true
RUN apt-get update && \
apt-get install -y libpcap-dev python-requests time file shellcheck git gcc-arm-linux-gnueabihf curl build-essential && \
apt-get install -y libpcap-dev python-requests time file shellcheck git gcc-arm-linux-gnueabihf curl build-essential python-pip && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN curl -Ls https://storage.googleapis.com/golang/go${GOVERSION}.linux-amd64.tar.gz | tar xz -C /usr/local
RUN go clean -i net && \
Expand All @@ -22,5 +22,6 @@ RUN go get -tags netgo \
github.com/client9/misspell/cmd/misspell && \
chmod a+wr --recursive /usr/local/go && \
rm -rf /go/pkg/ /go/src/
RUN pip install yapf==0.16.2 flake8==3.3.0
COPY build.sh /
ENTRYPOINT ["/build.sh"]
104 changes: 56 additions & 48 deletions extras/example/app/app.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import os
import socket
import sys
import requests
import random
import threading
import logging
import argparse
Expand All @@ -18,68 +16,78 @@
sessions = threading.local()
args = None


def do_redis():
redis.incr('hits')
return redis.get('hits')
redis.incr('hits')
return redis.get('hits')


def do_qotd():
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.settimeout(args.timeout)
s.connect((args.qotd, 4446))
s.send("Hello")
return s.recv(1024)
finally:
s.close()
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.settimeout(args.timeout)
s.connect((args.qotd, 4446))
s.send("Hello")
return s.recv(1024)
finally:
s.close()


def do_search():
if getattr(sessions, 'session', None) == None:
sessions.session = requests.Session()
r = sessions.session.get(args.search, timeout=args.timeout)
return r.text
if getattr(sessions, 'session', None) is None:
sessions.session = requests.Session()
r = sessions.session.get(args.search, timeout=args.timeout)
return r.text


def do_echo(text):
if getattr(sessions, 'session', None) == None:
sessions.session = requests.Session()
r = sessions.session.get(args.echo, data=text, timeout=args.timeout)
return r.text
if getattr(sessions, 'session', None) is None:
sessions.session = requests.Session()
r = sessions.session.get(args.echo, data=text, timeout=args.timeout)
return r.text


def ignore_error(f):
try:
return str(f())
except:
logging.error("Error executing function", exc_info=sys.exc_info())
return "Error"
try:
return str(f())
except:
logging.error("Error executing function", exc_info=sys.exc_info())
return "Error"


# this root is for the tracing demo
@app.route('/hello')
def hello():
qotd_msg = do_qotd()
qotd_msg = do_echo(qotd_msg)
return qotd_msg
qotd_msg = do_qotd()
qotd_msg = do_echo(qotd_msg)
return qotd_msg


# this is for normal demos
@app.route('/')
def root():
counter_future = pool.submit(do_redis)
search_future = pool.submit(do_search)
qotd_future = pool.submit(do_qotd)
echo_future = pool.submit(lambda: do_echo("foo"))
result = 'Hello World! I have been seen %s times.' % ignore_error(counter_future.result)
result += ignore_error(search_future.result)
result += ignore_error(qotd_future.result)
result += ignore_error(echo_future.result)
return result
counter_future = pool.submit(do_redis)
search_future = pool.submit(do_search)
qotd_future = pool.submit(do_qotd)
echo_future = pool.submit(lambda: do_echo("foo"))
result = 'Hello World! I have been seen %s times.' % ignore_error(
counter_future.result)
result += ignore_error(search_future.result)
result += ignore_error(qotd_future.result)
result += ignore_error(echo_future.result)
return result


if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('-redis', default="redis.weave.local")
parser.add_argument('-search', default="http://search.weave.local:80/")
parser.add_argument('-qotd', default="qotd.weave.local")
parser.add_argument('-echo', default="http://echo.weave.local:80/")
parser.add_argument('-timeout', default=0.5, type=float)
args = parser.parse_args()

logging.basicConfig(format='%(asctime)s %(levelname)s %(filename)s:%(lineno)d - %(message)s', level=logging.INFO)
WSGIRequestHandler.protocol_version = "HTTP/1.1"
app.run(host="0.0.0.0", port=80, debug=True)
parser = argparse.ArgumentParser()
parser.add_argument('-redis', default="redis.weave.local")
parser.add_argument('-search', default="http://search.weave.local:80/")
parser.add_argument('-qotd', default="qotd.weave.local")
parser.add_argument('-echo', default="http://echo.weave.local:80/")
parser.add_argument('-timeout', default=0.5, type=float)
args = parser.parse_args()

logfmt = '%(asctime)s %(levelname)s %(filename)s:%(lineno)d - %(message)s'
logging.basicConfig(format=logfmt, level=logging.INFO)
WSGIRequestHandler.protocol_version = "HTTP/1.1"
app.run(host="0.0.0.0", port=80, debug=True)
87 changes: 46 additions & 41 deletions extras/example/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,53 +7,58 @@
import socket
import sys


def do_request(s, args):
addrs = socket.getaddrinfo(args.target, args.port)
addrs = [a
for a in addrs
if a[0] == socket.AF_INET]
if len(addrs) <= 0:
logging.info("Could not resolve %s", args.target)
return
addr = random.choice(addrs)
url = "http://%s:%d%s" % (addr[4][0], args.port, args.path)
s.get(url, timeout=args.timeout)
logging.info("Did request %s", url)
addrs = socket.getaddrinfo(args.target, args.port)
addrs = [a for a in addrs if a[0] == socket.AF_INET]
if len(addrs) <= 0:
logging.info("Could not resolve %s", args.target)
return
addr = random.choice(addrs)
url = "http://%s:%d%s" % (addr[4][0], args.port, args.path)
s.get(url, timeout=args.timeout)
logging.info("Did request %s", url)


def do_requests(args):
s = requests.Session()
while True:
try:
if args.persist:
do_request(s, args)
else:
do_request(requests.Session(), args)
except:
logging.error("Error doing request", exc_info=sys.exc_info())
s = requests.Session()
while True:
try:
if args.persist:
do_request(s, args)
else:
do_request(requests.Session(), args)
except:
logging.error("Error doing request", exc_info=sys.exc_info())

time.sleep(args.period)
time.sleep(args.period)


def main():
parser = argparse.ArgumentParser()
parser.add_argument('-target', default="frontend.weave.local")
parser.add_argument('-port', default=80, type=int)
parser.add_argument('-path', default="/")
parser.add_argument('-concurrency', default=1, type=int)
parser.add_argument('-persist', default=True, type=bool)
parser.add_argument('-timeout', default=1.0, type=float)
parser.add_argument('-period', default=0.1, type=float)
args = parser.parse_args()

logging.info("Starting %d threads, targeting %s", args.concurrency, args.target)
threads = [threading.Thread(target=do_requests, args=(args,))
for i in range(args.concurrency)]
for thread in threads:
thread.start()
for thread in threads:
thread.join()
logging.info("Exiting")
parser = argparse.ArgumentParser()
parser.add_argument('-target', default="frontend.weave.local")
parser.add_argument('-port', default=80, type=int)
parser.add_argument('-path', default="/")
parser.add_argument('-concurrency', default=1, type=int)
parser.add_argument('-persist', default=True, type=bool)
parser.add_argument('-timeout', default=1.0, type=float)
parser.add_argument('-period', default=0.1, type=float)
args = parser.parse_args()

logging.info("Starting %d threads, targeting %s", args.concurrency,
args.target)
threads = [
threading.Thread(target=do_requests, args=(args, ))
for i in range(args.concurrency)
]
for thread in threads:
thread.start()
for thread in threads:
thread.join()
logging.info("Exiting")


if __name__ == "__main__":
logging.basicConfig(format='%(asctime)s %(levelname)s %(filename)s:%(lineno)d - %(message)s', level=logging.INFO)
main()
logfmt = '%(asctime)s %(levelname)s %(filename)s:%(lineno)d - %(message)s'
logging.basicConfig(format=logfmt, level=logging.INFO)
main()
17 changes: 7 additions & 10 deletions extras/example/echo/echo.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
import os
import socket
import sys
import random
import time
import threading
import logging

from flask import Flask
Expand All @@ -12,11 +6,14 @@

app = Flask(__name__)


@app.route('/')
def echo():
return request.data
return request.data


if __name__ == "__main__":
logging.basicConfig(format='%(asctime)s %(levelname)s %(filename)s:%(lineno)d - %(message)s', level=logging.INFO)
WSGIRequestHandler.protocol_version = "HTTP/1.0"
app.run(host="0.0.0.0", port=80, debug=True)
logfmt = '%(asctime)s %(levelname)s %(filename)s:%(lineno)d - %(message)s'
logging.basicConfig(format=logfmt, level=logging.INFO)
WSGIRequestHandler.protocol_version = "HTTP/1.0"
app.run(host="0.0.0.0", port=80, debug=True)
70 changes: 39 additions & 31 deletions extras/example/trace_app/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import socket
import sys
import requests
Expand All @@ -18,52 +17,61 @@

searchapps = ['http://searchapp:8080/']


def do_redis():
redis.incr('hits')
return redis.get('hits')
redis.incr('hits')
return redis.get('hits')


def do_qotd():
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.connect(("qotd.weave.local", 4446))
s.send("Hello")
return s.recv(1024)
finally:
s.close()
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.connect(("qotd.weave.local", 4446))
s.send("Hello")
return s.recv(1024)
finally:
s.close()


def do_search():
if getattr(sessions, 'session', None) == None:
sessions.session = requests.Session()
r = sessions.session.get(random.choice(searchapps))
return r.text
if getattr(sessions, 'session', None) is None:
sessions.session = requests.Session()
r = sessions.session.get(random.choice(searchapps))
return r.text


def do_echo(text):
r = requests.get("http://echo.weave.local/", data=text)
return r.text
r = requests.get("http://echo.weave.local/", data=text)
return r.text


def ignore_error(f):
try:
return str(f())
except:
logging.error("Error executing function", exc_info=sys.exc_info())
return "Error"
try:
return str(f())
except:
logging.error("Error executing function", exc_info=sys.exc_info())
return "Error"


# this root is for the tracing demo
@app.route('/hello')
def hello():
qotd_msg = do_qotd()
qotd_msg = do_echo(qotd_msg)
return qotd_msg
qotd_msg = do_qotd()
qotd_msg = do_echo(qotd_msg)
return qotd_msg


# this is for normal demos
@app.route('/')
def root():
#counter_future = pool.submit(do_redis)
#search_future = pool.submit(do_search)
result = do_echo(do_qotd())
return result
# counter_future = pool.submit(do_redis)
# search_future = pool.submit(do_search)
result = do_echo(do_qotd())
return result


if __name__ == "__main__":
logging.basicConfig(format='%(asctime)s %(levelname)s %(filename)s:%(lineno)d - %(message)s', level=logging.INFO)
WSGIRequestHandler.protocol_version = "HTTP/1.1"
app.run(host="0.0.0.0", port=80, debug=True)
logfmt = '%(asctime)s %(levelname)s %(filename)s:%(lineno)d - %(message)s'
logging.basicConfig(format=logfmt, level=logging.INFO)
WSGIRequestHandler.protocol_version = "HTTP/1.1"
app.run(host="0.0.0.0", port=80, debug=True)
3 changes: 2 additions & 1 deletion tools/build/golang/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ RUN apt-get update && \
unzip && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN pip install attrs pyhcl
RUN curl -fsSL -o shfmt https://github.com/mvdan/sh/releases/download/v1.3.0/shfmt_v1.3.0_linux_amd64 && \
RUN curl -fsSLo shfmt https://github.com/mvdan/sh/releases/download/v1.3.0/shfmt_v1.3.0_linux_amd64 && \
echo "b1925c2c405458811f0c227266402cf1868b4de529f114722c2e3a5af4ac7bb2 shfmt" | sha256sum -c && \
chmod +x shfmt && \
mv shfmt /usr/bin
RUN go clean -i net && \
Expand Down
Loading