Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
briar
briar
Commits
519837e8
Verified
Commit
519837e8
authored
Jan 07, 2022
by
Torsten Grote
Browse files
Add MailboxIntegrationTest against a real mailbox instance
parent
9fa54bf1
Pipeline
#8963
passed with stages
in 15 minutes
Changes
3
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
.gitlab-ci.yml
View file @
519837e8
...
...
@@ -62,7 +62,7 @@ android test:
when
:
on_failure
rules
:
-
if
:
'
$CI_PIPELINE_SOURCE
==
"schedule"'
when
:
on_success
when
:
manual
-
if
:
'
$CI_PIPELINE_SOURCE
==
"merge_request_event"'
changes
:
-
briar-android/**/*
...
...
@@ -85,35 +85,46 @@ test_reproducible:
.optional_tests
:
stage
:
optional_tests
before_script
:
-
set -e
-
export GRADLE_USER_HOME=$PWD/.gradle
cache
:
key
:
"
$CI_COMMIT_REF_SLUG"
paths
:
-
.gradle/wrapper
-
.gradle/caches
extends
:
.base-test
bridge test
:
extends
:
.optional_tests
rules
:
-
if
:
'
$CI_PIPELINE_SOURCE
==
"schedule"'
when
:
on_success
allow_failure
:
false
-
if
:
'
$CI_COMMIT_TAG
==
null'
when
:
manual
allow_failure
:
true
script
:
-
OPTIONAL_TESTS=org.briarproject.bramble.plugin.tor.BridgeTest ./gradlew --info bramble-java:test --tests BridgeTest
after_script
:
# these file change every time but should not be cached
-
rm -f $GRADLE_USER_HOME/caches/modules-2/modules-2.lock
-
rm -fr $GRADLE_USER_HOME/caches/*/plugin-resolution/
bridge test
:
mailbox integration test
:
extends
:
.optional_tests
rules
:
-
if
:
'
$CI_PIPELINE_SOURCE
==
"schedule"'
when
:
on_success
allow_failure
:
tru
e
allow_failure
:
fals
e
-
if
:
'
$CI_COMMIT_TAG
==
null'
when
:
manual
allow_failure
:
true
allow_failure
:
false
script
:
# start mailbox
-
cd /opt && git clone --depth 1 https://code.briarproject.org/briar/briar-mailbox.git briar-mailbox
-
cd briar-mailbox
-
mkdir -p /root/.local/share
# create directory that mailbox (currently) expects to exist
-
./gradlew run --args="--debug --setup-token 54686973206973206120736574757020746f6b656e20666f722042726961722e" &
-
export MAILBOX_PID=$!
# run mailbox integration test once mailbox has started
-
cd "$CI_PROJECT_DIR"
-
./wait-for-mailbox.sh
-
OPTIONAL_TESTS=org.briarproject.bramble.mailbox.MailboxIntegrationTest ./gradlew --info bramble-core:test --tests MailboxIntegrationTest
# kill mailbox in case there was an error before
-
kill -9 $MAILBOX_PID ||
true
pre_release_tests
:
extends
:
.optional_tests
script
:
-
OPTIONAL_TESTS=org.briarproject.bramble.plugin.tor.BridgeTest ./gradlew --info bramble-java:test --tests BridgeTest
only
:
-
tags
bramble-core/src/test/java/org/briarproject/bramble/mailbox/MailboxIntegrationTest.java
0 → 100644
View file @
519837e8
package
org.briarproject.bramble.mailbox
;
import
org.briarproject.bramble.api.WeakSingletonProvider
;
import
org.briarproject.bramble.api.contact.ContactId
;
import
org.briarproject.bramble.api.mailbox.MailboxProperties
;
import
org.briarproject.bramble.mailbox.MailboxApi.ApiException
;
import
org.briarproject.bramble.mailbox.MailboxApi.MailboxContact
;
import
org.briarproject.bramble.mailbox.MailboxApi.TolerableFailureException
;
import
org.briarproject.bramble.test.BrambleTestCase
;
import
org.junit.Before
;
import
org.junit.BeforeClass
;
import
org.junit.Test
;
import
java.io.IOException
;
import
java.util.Arrays
;
import
javax.annotation.Nonnull
;
import
javax.net.SocketFactory
;
import
okhttp3.OkHttpClient
;
import
static
java
.
util
.
Collections
.
emptyList
;
import
static
java
.
util
.
Collections
.
singletonList
;
import
static
java
.
util
.
concurrent
.
TimeUnit
.
MILLISECONDS
;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
getMailboxSecret
;
import
static
org
.
briarproject
.
bramble
.
test
.
TestUtils
.
isOptionalTestEnabled
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertThrows
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
junit
.
Assume
.
assumeTrue
;
public
class
MailboxIntegrationTest
extends
BrambleTestCase
{
private
final
static
String
URL_BASE
=
"http://127.0.0.1:8000"
;
private
final
static
String
SETUP_TOKEN
=
"54686973206973206120736574757020746f6b656e20666f722042726961722e"
;
private
final
OkHttpClient
client
=
new
OkHttpClient
.
Builder
()
.
socketFactory
(
SocketFactory
.
getDefault
())
.
connectTimeout
(
60_000
,
MILLISECONDS
)
.
build
();
private
final
WeakSingletonProvider
<
OkHttpClient
>
httpClientProvider
=
new
WeakSingletonProvider
<
OkHttpClient
>()
{
@Override
@Nonnull
public
OkHttpClient
createInstance
()
{
return
client
;
}
};
private
final
MailboxApiImpl
api
=
new
MailboxApiImpl
(
httpClientProvider
);
// needs to be static to keep values across different tests
private
static
MailboxProperties
ownerProperties
;
/**
* Called before each test to make sure the mailbox is setup once
* before starting with individual tests.
* {@link BeforeClass} needs to be static, so we can't use the API class.
*/
@Before
public
void
ensureSetup
()
throws
IOException
,
ApiException
{
// Skip this test unless it's explicitly enabled in the environment
assumeTrue
(
isOptionalTestEnabled
(
MailboxIntegrationTest
.
class
));
if
(
ownerProperties
!=
null
)
return
;
MailboxProperties
setupProperties
=
new
MailboxProperties
(
URL_BASE
,
SETUP_TOKEN
,
true
);
String
ownerToken
=
api
.
setup
(
setupProperties
);
ownerProperties
=
new
MailboxProperties
(
URL_BASE
,
ownerToken
,
true
);
}
@Test
public
void
testStatus
()
throws
Exception
{
assertTrue
(
api
.
checkStatus
(
ownerProperties
));
}
@Test
public
void
testContactApi
()
throws
Exception
{
ContactId
contactId1
=
new
ContactId
(
1
);
ContactId
contactId2
=
new
ContactId
(
2
);
MailboxContact
mailboxContact1
=
getMailboxContact
(
contactId1
);
MailboxContact
mailboxContact2
=
getMailboxContact
(
contactId2
);
// no contacts initially
assertEquals
(
emptyList
(),
api
.
getContacts
(
ownerProperties
));
// added contact gets returned
api
.
addContact
(
ownerProperties
,
mailboxContact1
);
assertEquals
(
singletonList
(
contactId1
),
api
.
getContacts
(
ownerProperties
));
// second contact also gets returned
api
.
addContact
(
ownerProperties
,
mailboxContact2
);
assertEquals
(
Arrays
.
asList
(
contactId1
,
contactId2
),
api
.
getContacts
(
ownerProperties
));
// after both contacts get deleted, the list is empty again
api
.
deleteContact
(
ownerProperties
,
contactId1
);
api
.
deleteContact
(
ownerProperties
,
contactId2
);
assertEquals
(
emptyList
(),
api
.
getContacts
(
ownerProperties
));
// deleting again is tolerable
assertThrows
(
TolerableFailureException
.
class
,
()
->
api
.
deleteContact
(
ownerProperties
,
contactId2
));
}
private
MailboxContact
getMailboxContact
(
ContactId
contactId
)
{
return
new
MailboxContact
(
contactId
,
getMailboxSecret
(),
getMailboxSecret
(),
getMailboxSecret
());
}
}
wait-for-mailbox.sh
0 → 100755
View file @
519837e8
#!/bin/bash
set
-e
URL
=
"http://127.0.0.1:8000/status"
attempt_counter
=
0
max_attempts
=
200
# 10min - CI for mailbox currently takes ~5min
echo
"Waiting for mailbox to come online at
$URL
"
until
[[
"
$(
curl
-s
-o
/dev/null
-w
'%{http_code}'
$URL
)
"
==
"401"
]]
;
do
if
[
${
attempt_counter
}
-eq
${
max_attempts
}
]
;
then
echo
"Timed out waiting for mailbox"
exit
1
fi
printf
'.'
attempt_counter
=
$((
attempt_counter
+
1
))
sleep
3
done
echo
"Mailbox started"
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment