Commit cca2c471 authored by David Stainton's avatar David Stainton

Add async decoy send test and fix readme

parent ce911400
Pipeline #975 passed with stage
in 4 minutes and 31 seconds
......@@ -14,17 +14,19 @@ Katzenpost Mix Network Client Library
optional docker tests
---------------------
To run the option docker tests firstly, see our docker repo
To run the optional docker tests firstly, see our docker repo
and start your local dockerized mix network:
https://github.com/katzenpost/docker
A couple of minutes after startup run the following commands:
A couple of minutes after startup run the tests like this:
::
GORACE=history_size=7 go test -v -tags=docker_test -race -run TestDockerClientBlockingSendReceive
GORACE=history_size=7 go test -v -tags=docker_test -race -run TestDockerClientBlockingSendReceiveWithDecoyTraffic
GORACE=history_size=7 go test -v -tags=docker_test -race -run TestDockerClientAsyncSendReceive
GORACE=history_size=7 go test -v -tags=docker_test -race -run TestDockerClientAsyncSendReceiveWithDecoyTraffic
license
=======
......
......@@ -19,6 +19,8 @@
package client
import (
"bytes"
"sync"
"testing"
"github.com/katzenpost/client/config"
......@@ -30,7 +32,6 @@ import (
func TestDockerClientBlockingSendReceive(t *testing.T) {
require := require.New(t)
// Load catshadow config file.
cfg, err := config.LoadFile("testdata/client.toml")
require.NoError(err)
......@@ -52,7 +53,6 @@ func TestDockerClientBlockingSendReceive(t *testing.T) {
func TestDockerClientBlockingSendReceiveWithDecoyTraffic(t *testing.T) {
require := require.New(t)
// Load catshadow config file.
cfg, err := config.LoadFile("testdata/client.toml")
require.NoError(err)
......@@ -75,7 +75,6 @@ func TestDockerClientBlockingSendReceiveWithDecoyTraffic(t *testing.T) {
func TestDockerClientAsyncSendReceive(t *testing.T) {
require := require.New(t)
// Load catshadow config file.
cfg, err := config.LoadFile("testdata/client.toml")
require.NoError(err)
......@@ -105,3 +104,47 @@ func TestDockerClientAsyncSendReceive(t *testing.T) {
require.True(utils.CtIsZero(event2.Payload))
require.NoError(event2.Err)
}
func TestDockerClientAsyncSendReceiveWithDecoyTraffic(t *testing.T) {
require := require.New(t)
cfg, err := config.LoadFile("testdata/client.toml")
require.NoError(err)
cfg, linkKey := AutoRegisterRandomClient(cfg)
cfg.Debug.DisableDecoyTraffic = false
client, err := New(cfg)
require.NoError(err)
clientSession, err := client.NewSession(linkKey)
require.NoError(err)
desc, err := clientSession.GetService("loop")
require.NoError(err)
msgID, err := clientSession.SendUnreliableMessage(desc.Name, desc.Provider, []byte("hello"))
require.NoError(err)
t.Logf("sent message ID %x", msgID)
var wg sync.WaitGroup
wg.Add(2)
go func() {
for eventRaw := range clientSession.EventSink {
switch event := eventRaw.(type) {
case *session.MessageSentEvent:
if bytes.Equal(msgID[:], event.MessageID[:]) {
require.NoError(event.Err)
wg.Done()
}
case *session.MessageReplyEvent:
if bytes.Equal(msgID[:], event.MessageID[:]) {
require.NoError(event.Err)
require.True(utils.CtIsZero(event.Payload))
wg.Done()
return
}
}
}
}()
wg.Wait()
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment