Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
teivah
committed
Dec 11, 2018
1 parent
6d7ab5d
commit 57ebee4
Showing
7 changed files
with
158 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,24 @@ | ||
package rxgo | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"fmt" | ||
"github.com/reactivex/rxgo/handlers" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/reactivex/rxgo/options" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestConnect(t *testing.T) { | ||
just := Just(1, 2, 3).Publish() | ||
obs := Just(1, 2, 3).Publish() | ||
got1 := make([]interface{}, 0) | ||
got2 := make([]interface{}, 0) | ||
|
||
just.Subscribe(handlers.NextFunc(func(i interface{}) { | ||
obs.Subscribe(handlers.NextFunc(func(i interface{}) { | ||
got1 = append(got1, i) | ||
})) | ||
|
||
just.Subscribe(handlers.NextFunc(func(i interface{}) { | ||
got2 = append(got2, i) | ||
})) | ||
|
||
just.Connect().Block() | ||
assert.Equal(t, []interface{}{1, 2, 3}, got1) | ||
assert.Equal(t, []interface{}{1, 2, 3}, got2) | ||
} | ||
|
||
func TestConnectOnError(t *testing.T) { | ||
just := Just(1, 2, 3, errors.New("foo"), 4).Publish() | ||
got1 := make([]interface{}, 0) | ||
got2 := make([]interface{}, 0) | ||
|
||
just.Subscribe(handlers.NextFunc(func(i interface{}) { | ||
got1 = append(got1, i) | ||
})) | ||
|
||
just.Subscribe(handlers.NextFunc(func(i interface{}) { | ||
got2 = append(got2, i) | ||
})) | ||
time.Sleep(200 * time.Millisecond) // Pause the observer on purpose | ||
}), options.WithBufferBackpressureStrategy(1)) | ||
//}), options.WithDropBackpressureStrategy()) | ||
obs.Connect() | ||
|
||
just.Connect().Block() | ||
assert.Equal(t, []interface{}{1, 2, 3}, got1) | ||
assert.Equal(t, []interface{}{1, 2, 3}, got2) | ||
time.Sleep(500 * time.Millisecond) // Ugly wait just for the example | ||
fmt.Printf("%v\n", got1) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters