Skip to content

Commit

Permalink
fallback to ipv4 in client/server tests, through a cabal flag, and us…
Browse files Browse the repository at this point in the history
…e in CI
  • Loading branch information
alpmestan committed Nov 27, 2020
1 parent 91d9327 commit 1ff9db6
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 20 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-syntax-for-github-actions
name: CI
on: [push, pull_request]
on: [push]

jobs:
ci:
Expand Down Expand Up @@ -38,12 +38,12 @@ jobs:
- name: Generate C++ code from thrift files
run: make thrift-cpp
- name: Build everything up to thrift-compiler
run: cabal build exe:thrift-compiler
run: cabal build --project-file=ci.cabal.project exe:thrift-compiler
- name: Generate Haskell code from thrift files
run: make thrift-hs
- name: Build all packages
run: cabal build all
run: cabal build --project-file=ci.cabal.project all
- name: Run testsuites
run: cabal test mangle fb-util thrift-compiler thrift-lib thrift-server --keep-going
run: cabal test --project-file=ci.cabal.project mangle fb-util thrift-compiler thrift-lib thrift-server --keep-going
# --keep-going is necessary to avoid stopping at the first failing
# testsuite('s package?)
9 changes: 4 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ util::

thrift:: thrift-cpp thrift-hs

THRIFT_COMPILE = $(CABAL) new-run exe:thrift-compiler --
THRIFT_COMPILE = $(CABAL) run exe:thrift-compiler --

thrift-hs::
$(THRIFT_COMPILE) --hs --use-int \
$(THRIFT_COMPILE) --hs \
lib/if/RpcOptions.thrift \
-o lib
$(THRIFT_COMPILE) --hs --use-int \
$(THRIFT_COMPILE) --hs \
lib/if/ApplicationException.thrift \
-o lib
$(THRIFT_COMPILE) --hs --use-int \
Expand All @@ -31,11 +31,10 @@ thrift-hs::
$(THRIFT_COMPILE) --hs --use-int \
lib/test/if/echoer.thrift \
-o lib/test
$(THRIFT_COMPILE) --hs --use-int \
$(THRIFT_COMPILE) --hs \
server/test/if/hash_map.thrift \
-o server/test


thrift-cpp::
cd lib && thrift1 -I . --gen mstch_cpp2 \
-o if \
Expand Down
17 changes: 17 additions & 0 deletions ci.cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
packages:
common/util/fb-util.cabal
common/mangle/mangle.cabal
lib/thrift-lib.cabal
server/thrift-server.cabal
compiler/thrift-compiler.cabal
util/thrift-util.cabal

tests: true

-- IPV6 is disabled in the Github Actions environment,
-- so we make sure the appropriate tests in those packages
-- turn to IPV4.
package thrift-lib
flags: +tests_use_ipv4
package thrift-server
flags: +tests_use_ipv4
6 changes: 0 additions & 6 deletions common/util/fb-util.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -327,12 +327,6 @@ test-suite list
type: exitcode-stdio-1.0
main-is: ListTest.hs
ghc-options: -main-is ListTest
test-suite encoding
import: fb-haskell, test-common
type: exitcode-stdio-1.0
main-is: EncodingTest.hs
ghc-options: -main-is EncodingTest
other-modules: EncodingLib
test-suite concurrent
import: fb-haskell, test-common
type: exitcode-stdio-1.0
Expand Down
3 changes: 2 additions & 1 deletion lib/test/HeaderChannelTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Control.Monad.Trans.Class
import Data.Proxy
import Foreign
import Foreign.C
import Network (testServerHost)
import Test.HUnit
import TestRunner
import Util.EventBase
Expand All @@ -24,7 +25,7 @@ myRpcOptions = defaultRpcOptions { rpc_timeout = 5000 }

mySvcConf :: Int -> HeaderConfig Calculator
mySvcConf port = HeaderConfig
{ headerHost = "::1"
{ headerHost = testServerHost
, headerPort = port
, headerProtocolId = compactProtocolId
, headerConnTimeout = 5000
Expand Down
12 changes: 12 additions & 0 deletions lib/test/Network.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{-# LANGUAGE CPP #-}
module Network where

import Data.ByteString.Char8 (ByteString, pack)

testServerHost :: ByteString
testServerHost = pack
#ifdef IPV4
"127.0.0.1"
#else
"::1"
#endif
8 changes: 6 additions & 2 deletions lib/test/cpp/MathServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ class CalculatorServiceHandler : public CalculatorSvIf {
};

ScopedServerInterfaceThread* createServer(int64_t& /*port*/) {
return new ScopedServerInterfaceThread(
make_shared<CalculatorServiceHandler>());
return new ScopedServerInterfaceThread( make_shared<CalculatorServiceHandler>()
#ifdef IPV4
, "127.0.0.1" ); // necessary to force IPV4 in e.g CI/docker
#else
, "::1" );
#endif
}

extern "C" {
Expand Down
12 changes: 12 additions & 0 deletions lib/thrift-lib.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ library
hashable >=1.2.7.0 && <1.4,
vector ^>=0.12.0.1

flag tests_use_ipv4
description: Force tests to use IPV4 whenever bringing thrift clients/servers up
default: False
manual: True

common test-common
hs-source-dirs:
test,
Expand All @@ -130,6 +135,7 @@ common test-common
../compiler/test/fixtures/gen-hs2
-- ^^^ for HsTest.Types
other-modules:
Network
TestRunner
TestChannel
Math.Types
Expand Down Expand Up @@ -176,6 +182,12 @@ common test-common
STMonadTrans
ghc-options: -threaded

if flag(tests_use_ipv4)
-- for test/Network.hs
cpp-options: -DIPV4
-- for test/cpp/MathServer.cpp
cxx-options: -DIPV4

test-suite channel
import: fb-haskell, test-common
type: exitcode-stdio-1.0
Expand Down
3 changes: 2 additions & 1 deletion server/test/DanglingPointerTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Data.IORef
import Data.Text (Text)

import Facebook.Init
import Network (testServerHost)
import Test.HUnit
import TestRunner

Expand Down Expand Up @@ -49,7 +50,7 @@ runServer evb st keys protId =
let
conf :: HeaderConfig HashMapService
conf = HeaderConfig
{ headerHost = "::1"
{ headerHost = testServerHost
, headerPort = serverPort
, headerProtocolId = protId
, headerConnTimeout = 5000
Expand Down
12 changes: 12 additions & 0 deletions server/test/Network.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{-# LANGUAGE CPP #-}
module Network where

import Data.ByteString.Char8 (ByteString, pack)

testServerHost :: ByteString
testServerHost = pack
#ifdef IPV4
"127.0.0.1"
#else
"::1"
#endif
3 changes: 2 additions & 1 deletion server/test/ServerTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Control.Monad.Trans.Class
import Data.Either

import Facebook.Init
import Network (testServerHost)
import Test.HUnit
import TestRunner

Expand Down Expand Up @@ -33,7 +34,7 @@ withTestServer serverOptions action = do
mkHeaderConfig :: Int -> ProtocolId -> HeaderConfig t
mkHeaderConfig port protId =
HeaderConfig
{ headerHost = "::1"
{ headerHost = testServerHost
, headerPort = port
, headerProtocolId = protId
, headerConnTimeout = 5000
Expand Down
10 changes: 10 additions & 0 deletions server/thrift-server.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,16 @@ library
-- when running hsc2hs on Thrift.Server.ProcessorCallback
extra-libraries: boost_context

flag tests_use_ipv4
description: Force tests to use IPV4 whenever bringing thrift clients/servers up
default: False
manual: True

common test-common
hs-source-dirs: test, test/github, test/gen-hs2, ../lib/test/gen-hs2, ../lib/test

other-modules: Facebook.Init
Network
TestRunner
CalculatorHandler
EchoHandler
Expand Down Expand Up @@ -105,6 +111,10 @@ common test-common
thrift-server,
transformers,
unordered-containers
if flag(tests_use_ipv4)
-- for test/Network.hs
cpp-options: -DIPV4


test-suite dangling-pointer
import: fb-haskell, test-common
Expand Down

0 comments on commit 1ff9db6

Please sign in to comment.