From cb365a5feef21ee1b618f8fb6a3652a7c3dbd2e2 Mon Sep 17 00:00:00 2001 From: vyzo Date: Sun, 14 Jan 2018 02:01:42 +0200 Subject: [PATCH] remove faulty tests --- floodsub_test.go | 98 ------------------------------------------------ 1 file changed, 98 deletions(-) diff --git a/floodsub_test.go b/floodsub_test.go index 6d58657..1bf1847 100644 --- a/floodsub_test.go +++ b/floodsub_test.go @@ -392,104 +392,6 @@ func TestValidate(t *testing.T) { } } -func TestValidateTimeout(t *testing.T) { - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - - hosts := getNetHosts(t, ctx, 2) - psubs := getPubsubs(ctx, hosts) - - connect(t, hosts[0], hosts[1]) - topic := "foobar" - - cases := []struct { - timeout time.Duration - msg []byte - validates bool - }{ - {75 * time.Millisecond, []byte("this better time out"), false}, - {150 * time.Millisecond, []byte("this should work"), true}, - } - - for _, tc := range cases { - sub, err := psubs[1].Subscribe(topic, WithValidator(func(ctx context.Context, msg *Message) bool { - time.Sleep(100 * time.Millisecond) - return true - }), WithValidatorTimeout(tc.timeout)) - if err != nil { - t.Fatal(err) - } - - time.Sleep(time.Millisecond * 50) - - p := psubs[0] - err = p.Publish(topic, tc.msg) - if err != nil { - t.Fatal(err) - } - - select { - case msg := <-sub.ch: - if !tc.validates { - t.Log(msg) - t.Error("expected message validation to filter out the message") - } - case <-time.After(333 * time.Millisecond): - if tc.validates { - t.Error("expected message validation to accept the message") - } - } - - // important: cancel! - // otherwise the message will still be filtered by the other subscription - sub.Cancel() - } - -} - -func TestValidateCancel(t *testing.T) { - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - - hosts := getNetHosts(t, ctx, 2) - psubs := getPubsubs(ctx, hosts) - - connect(t, hosts[0], hosts[1]) - topic := "foobar" - - sub, err := psubs[1].Subscribe(topic, WithValidator(func(ctx context.Context, msg *Message) bool { - <-ctx.Done() - return true - })) - if err != nil { - t.Fatal(err) - } - - time.Sleep(time.Millisecond * 50) - - testmsg := []byte("this is a legal message") - validates := false // message for which the validator times our are discarded - - p := psubs[0] - - err = p.Publish(topic, testmsg) - if err != nil { - t.Fatal(err) - } - - select { - case msg := <-sub.ch: - if !validates { - t.Log(msg) - t.Error("expected message validation to filter out the message") - } - case <-time.After(333 * time.Millisecond): - if validates { - t.Error("expected message validation to accept the message") - } - } -} - func TestValidateOverload(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel()