Prechádzať zdrojové kódy

Port crystal tests to docker (#3379)

* Port crystal tests to docker

* Re-enable crystal tests in travis
Michael Hixson 7 rokov pred
rodič
commit
7d47566a09

+ 3 - 3
.travis.yml

@@ -37,9 +37,9 @@ env:
     # - "TESTDIR=Clojure/pedestal"
     # - "TESTDIR=Clojure/aleph"
     # - "TESTDIR=Clojure/reitit"
-    # - "TESTDIR=Crystal/amber"
-    # - "TESTDIR=Crystal/crystal"
-    # - "TESTDIR=Crystal/kemal"
+     - "TESTDIR=Crystal/amber"
+     - "TESTDIR=Crystal/crystal"
+     - "TESTDIR=Crystal/kemal"
      - "TESTDIR=D/vibed"
      - "TESTDIR=D/hunt"
      - "TESTDIR=D/collie"

+ 14 - 0
frameworks/Crystal/amber/amber.dockerfile

@@ -0,0 +1,14 @@
+FROM tfb/crystal-lang:latest
+
+ADD ./ /amber
+WORKDIR /amber
+
+ENV GC_MARKERS 1
+ENV AMBER_ENV production
+ENV DATABASE_URL postgres://benchmarkdbuser:benchmarkdbpass@TFB-database:5432/hello_world
+
+RUN apt-get install -y libyaml-dev
+
+RUN shards build amber --release --no-debug
+
+CMD bash run.sh

+ 0 - 1
frameworks/Crystal/amber/benchmark_config.json

@@ -2,7 +2,6 @@
   "framework": "amber",
   "tests": [{
     "default": {
-      "setup_file": "setup",
       "json_url": "/json",
       "db_url": "/db",
       "query_url": "/queries?queries=",

+ 7 - 0
frameworks/Crystal/amber/run.sh

@@ -0,0 +1,7 @@
+#!/bin/bash
+
+for i in $(seq 1 $(nproc --all)); do
+  ./bin/amber &
+done
+
+wait

+ 0 - 17
frameworks/Crystal/amber/setup.sh

@@ -1,17 +0,0 @@
-#!/bin/bash
-
-fw_depends postgresql crystal
-
-export GC_MARKERS=1
-
-export AMBER_ENV=production
-
-export DATABASE_URL=postgres://benchmarkdbuser:benchmarkdbpass@TFB-database:5432/hello_world
-
-shards build amber --release --no-debug
-
-for i in $(seq 1 $(nproc --all)); do
-  ./bin/amber &
-done
-
-wait

+ 0 - 2
frameworks/Crystal/crystal/benchmark_config.json

@@ -2,7 +2,6 @@
   "framework": "crystal",
   "tests": [{
     "default": {
-      "setup_file": "setup",
       "json_url": "/json",
       "db_url": "/db",
       "query_url": "/queries?queries=",
@@ -26,7 +25,6 @@
       "versus": "crystal"
     },
     "radix": {
-      "setup_file": "setup_radix",
       "json_url": "/json",
       "db_url": "/db",
       "query_url": "/queries?queries=",

+ 11 - 0
frameworks/Crystal/crystal/crystal-radix.dockerfile

@@ -0,0 +1,11 @@
+FROM tfb/crystal-lang:latest
+
+ADD ./ /crystal
+WORKDIR /crystal
+
+ENV GC_MARKERS 1
+
+RUN shards install
+RUN crystal build --release --no-debug server_radix.cr -o server_radix.out
+
+CMD bash run-radix.sh

+ 11 - 0
frameworks/Crystal/crystal/crystal.dockerfile

@@ -0,0 +1,11 @@
+FROM tfb/crystal-lang:latest
+
+ADD ./ /crystal
+WORKDIR /crystal
+
+ENV GC_MARKERS 1
+
+RUN shards install
+RUN crystal build --release --no-debug server.cr -o server.out
+
+CMD bash run.sh

+ 7 - 0
frameworks/Crystal/crystal/run-radix.sh

@@ -0,0 +1,7 @@
+#!/bin/bash
+
+for i in $(seq 1 $(nproc --all)); do
+  ./server_radix.out &
+done
+
+wait

+ 7 - 0
frameworks/Crystal/crystal/run.sh

@@ -0,0 +1,7 @@
+#!/bin/bash
+
+for i in $(seq 1 $(nproc --all)); do
+  ./server.out &
+done
+
+wait

+ 0 - 15
frameworks/Crystal/crystal/setup.sh

@@ -1,15 +0,0 @@
-#!/bin/bash
-
-fw_depends postgresql crystal
-
-shards install
-
-crystal build --release --no-debug server.cr -o server.out
-
-export GC_MARKERS=1
-
-for i in $(seq 1 $(nproc --all)); do
-  ./server.out &
-done
-
-wait

+ 0 - 15
frameworks/Crystal/crystal/setup_radix.sh

@@ -1,15 +0,0 @@
-#!/bin/bash
-
-fw_depends postgresql crystal
-
-shards install
-
-crystal build --release --no-debug server_radix.cr -o server_radix.out
-
-export GC_MARKERS=1
-
-for i in $(seq 1 $(nproc --all)); do
-  ./server_radix.out &
-done
-
-wait

+ 0 - 1
frameworks/Crystal/kemal/benchmark_config.json

@@ -2,7 +2,6 @@
   "framework": "kemal",
   "tests": [{
     "default": {
-      "setup_file": "setup-postgres",
       "json_url": "/json",
       "db_url": "/db",
       "query_url": "/queries?queries=",

+ 12 - 0
frameworks/Crystal/kemal/kemal.dockerfile

@@ -0,0 +1,12 @@
+FROM tfb/crystal-lang:latest
+
+ADD ./ /kemal
+WORKDIR /kemal
+
+ENV GC_MARKERS 1
+ENV KEMAL_ENV production
+
+RUN shards install
+RUN crystal build --release --no-debug server-postgres.cr
+
+CMD bash run.sh

+ 7 - 0
frameworks/Crystal/kemal/run.sh

@@ -0,0 +1,7 @@
+#!/bin/bash
+
+for i in $(seq 1 $(nproc --all)); do
+  ./server-postgres -p 8080 &
+done
+
+wait

+ 0 - 116
frameworks/Crystal/kemal/server-redis.cr

@@ -1,116 +0,0 @@
-require "kemal"
-require "redis"
-
-# Compose Objects (like Hash) to have a to_json method
-require "json/to_json"
-
-REDIS = Redis.new
-
-class CONTENT
-  UTF8  = "; charset=UTF-8"
-  JSON  = "application/json"
-  PLAIN = "text/plain"
-  HTML  = "text/html" + UTF8
-end
-
-ID_MAXIMUM = 10_000
-
-private def random_world
-  id = rand(1..ID_MAXIMUM)
-  num = REDIS.get("world:#{id}")
-  {id: id, randomNumber: num}
-end
-
-private def set_world(world)
-  id = "world:#{world[:id]}"
-  REDIS.set(id, world[:randomNumber])
-  world
-end
-
-private def fortunes
-  data = [] of NamedTuple(id: Int32, message: String)
-
-  REDIS.lrange("fortunes", 0, -1).each_with_index do |e, i|
-    data.push({id: i + 1, message: e.to_s})
-  end
-  data
-end
-
-private def sanitized_query_count(request)
-  queries = request.params.query["queries"].as(String)
-  queries = queries.to_i? || 1
-  queries.clamp(1..500)
-end
-
-before_all do |env|
-  env.response.headers["Server"] = "Kemal"
-  env.response.headers["Date"] = Time.now.to_s
-end
-
-#
-# Basic Tests
-#
-
-# Test 1: JSON Serialization
-get "/json" do |env|
-  env.response.content_type = CONTENT::JSON
-  {message: "Hello, World!"}.to_json
-end
-
-# Test 6: Plaintext
-get "/plaintext" do |env|
-  env.response.content_type = CONTENT::PLAIN
-  "Hello, World!"
-end
-
-#
-# Redis DatabaseTests
-#
-
-# Redis Test 2: Single database query
-get "/db" do |env|
-  env.response.content_type = CONTENT::JSON
-  random_world.to_json
-end
-
-# Redis Test 3: Multiple database query
-get "/queries" do |env|
-  results = (1..sanitized_query_count(env)).map do
-    random_world
-  end
-
-  env.response.content_type = CONTENT::JSON
-  results.to_json
-end
-
-# Redis Test 4: Fortunes
-get "/fortunes" do |env|
-  data = fortunes
-
-  additional_fortune = {
-    id:      0,
-    message: "Additional fortune added at request time.",
-  }
-  data.push(additional_fortune)
-
-  data.sort_by! { |fortune| fortune[:message] }
-
-  render "views/fortunes.ecr"
-end
-
-# Redis Test 5: Database Updates
-get "/updates" do |env|
-  updated = (1..sanitized_query_count(env)).map do
-    set_world({id: random_world[:id], randomNumber: rand(1..ID_MAXIMUM)})
-  end
-
-  env.response.content_type = CONTENT::JSON
-  updated.to_json
-end
-
-Kemal.config do |cfg|
-  cfg.serve_static = false
-  cfg.logging = false
-end
-
-Kemal.run { |cfg| cfg.server.not_nil!.bind(reuse_port: true) }

+ 0 - 17
frameworks/Crystal/kemal/setup-postgres.sh

@@ -1,17 +0,0 @@
-#!/bin/bash
-
-fw_depends postgresql crystal
-
-shards install
-
-crystal build --release --no-debug server-postgres.cr
-
-export GC_MARKERS=1
-
-export KEMAL_ENV=production
-
-for i in $(seq 1 $(nproc --all)); do
-  ./server-postgres -p 8080 &
-done
-
-wait

+ 0 - 20
frameworks/Crystal/kemal/setup-redis.sh

@@ -1,20 +0,0 @@
-#!/bin/bash
-
-# This redis implementation works but there is currently no redis installation
-# for the benchmark suite
-
-fw_depends crystal
-
-shards install
-
-crystal build --release --no-debug server-redis.cr
-
-export GC_MARKERS=1
-
-export KEMAL_ENV=production
-
-for i in $(seq 1 $(nproc --all)); do
-  ./server-redis &
-done
-
-wait

+ 7 - 0
toolset/setup/docker/languages/crystal-lang.dockerfile

@@ -0,0 +1,7 @@
+FROM tfb/base:latest
+
+RUN mkdir /crystal-lang
+WORKDIR /crystal-lang
+RUN curl -sL https://github.com/crystal-lang/crystal/releases/download/v0.24.1/crystal-0.24.1-2-linux-x86_64.tar.gz | tar xz
+ENV CRYSTAL_HOME=/crystal-lang/crystal-0.24.1
+ENV PATH="${CRYSTAL_HOME}/bin:${PATH}"