Austin Clojure Meetup Message Board › WhatTheFn

WhatTheFn

Norman R.
normanrichards
Austin, TX
Post #: 52
I spent some time this morning playing with clojail, and I'm comfortable that we'll be able to use it relatively easily. I also looked over the source for 4clojure, try-clojure as well as our very own Paul Bostrom's cwo web repl to see how they are making use of clojail.

Norman R.
normanrichards
Austin, TX
Post #: 54
Here's some notes on creating a basic compojure app on DigitalOcean. I think i copied everything down.

add ssh keys on digital ocean
create droplet with latest ubuntu, note IP address and ssh in:

as root:
adduser clojure --disabled-password --gecos ""

apt-get install nginx
apt-get install openjdk-7-jdk

rm /etc/nginx/sites-enabled/default
cat /etc/nginx/sites-enabled/ring << EOF
upstream ring {
server 127.0.0.1:3000;
}

server {
listen 80;
server_name localhost;
location / {
proxy_pass http://ring;...
proxy_read_timeout 180;
}
}
EOF

ln -s /etc/nginx/sites-available/ring /etc/nginx/sites-enabled/ring
service nginx start

su - clojure
wget https://raw.github.co...­ -O /usr/local/bin/lein
chmod +x /usr/local/bin/lein
lein new compojure clojurecup
cd clojurecup
lein ring server-headless


app is running

Norman R.
normanrichards
Austin, TX
Post #: 55
Ok, I tried out test.generative this morning. I think it has some potential to work for us, but I'll have to play with it some more. Here's how far I got. Let's suppose I have a function that is supposed to add two integers, but it fails when x is twice y:

(defn bad-adder [x y]
(if (= x (* 2 y))
(* x y)
(+ x y)))

I write a spec that says that I expect a and b to be small numbers and bad adder should return the sum: (imagine that the assert function is the target function and bad-adder is the user's guess, even though for these specific functions it's reversed)

(defspec bad-adder-works
bad-adder
[^short a ^short b]
(assert (= (+ a b) %)))

Here's a wrapper around one of the test-generative runner that will run tests on one thread for up to 2 seconds:

(defn test-it []
(try
(runner/run 1 2000 #'bad-adder-works)
(catch clojure.lang.ExceptionInfo e
(.getData e))))

Amazingly, it finds an error case:

> (test-it)
{:exception #<AssertionError java.lang.AssertionError: Assert failed: (= (+ a b) %)>, :iter 152576, :seed 1337011249, :test gen/bad-adder-works, :input [3212 1606]}

If I change my failure case around, of course I can sometimes get a failure to find a failure:

> (test-it)
{:iter 255345, :seed -1288039320, :test gen/bad-adder-works}

But it's pretty impressive. I need to test more to see how this will work with clojail and the kind of functions we will be working with. However, I'm quite encouraged as was skeptical at how well generative testing would work.












Norman R.
normanrichards
Austin, TX
Post #: 57
Some notes on the DigitalOcean setup from friday. I made a mistake with sites-enabled and sites-available when copying over the setup commands. For nginx on ubuntu, create the file under sites-available and symlink it in sites-available.


apt-get install emacs git tmux

We also installed emacs (so I could more easily edit files) and tmux. We'll run the server in a tmux session so we can all have easy access to it. We might create a proper service later, but using tmux means we'll be able to debug and watch the server more easily.


We also created a key-pair on the test machine and pushed it to deveo. This allows us to "git checkout" the deploy branch (we're using master, again for speed) and immediately update the app.

Powered by mvnForum

Our Sponsors

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy