PubSub

Краен срок
21.11.2016 21:00

Срокът за предаване на решения е отминал

Направете тип PubSub за изпращане на string съобщения до множество получатели. Този тип трябва да има два метода: Subscribe() и Publish().

Subscribe() връща небуфериран канал за четене <-chan string и се използва за регистриране на нов "слушател". Publish() връща небуфериран канал за писане chan<- string, чрез който могат да се изпращат съобщения до всички регистрирани слушатели.

Напишете и функция NewPubSub(), която да връща инициализиран *PubSub, т.е. служи като конструктор на типа.

Пример:

ps := NewPubSub()
a := ps.Subscribe()
b := ps.Subscribe()
c := ps.Subscribe()
go func() {
    ps.Publish() <- "wat"
    ps.Publish() <- ("wat" + <-c)
}()
fmt.Printf("A recieved %s, B recieved %s and we ignore C!\n", <-a, <-b)
fmt.Printf("A recieved %s, B recieved %s and C received %s\n", <-a, <-b, <-c)

би трябвало да изведе:

A recieved wat, B recieved wat and we ignore C!
A recieved watwat, B recieved watwat and C received watwat

Уточнение: за улеснение, очакваме изпращането на едно съобщение или регистрирането на нов слушател да се случат чак след като всички регистрирани слушатели са прочели предишното съобщение. С други думи, не търсим ефективност, а коректност.

Решения

Радостина Димова
  • Некоректно
  • 5 успешни тест(а)
  • 1 неуспешни тест(а)
Радостина Димова
package main
type PubSub struct {
write chan string
subscribers []chan string
}
func (p *PubSub) Subscribe() <-chan string {
channel := make(chan string)
p.subscribers = append(p.subscribers, channel)
return channel
}
func (p *PubSub) Publish() chan<- string {
return p.write
}
func NewPubSub() *PubSub {
p := new(PubSub)
p.write = make(chan string)
p.subscribers = make([]chan string, 0)
go distributeMessages(p)
return p
}
func distributeMessages(p *PubSub) {
for message := range p.write {
for _, sub := range p.subscribers {
sub <- message
}
}
}
PASS
ok  	_/tmp/d20161125-30451-12r8bgf	0.002s
PASS
ok  	_/tmp/d20161125-30451-12r8bgf	0.003s
PASS
ok  	_/tmp/d20161125-30451-12r8bgf	0.103s
panic: test timed out after 1s

goroutine 33 [running]:
panic(0x4eae80, 0xc4200a8010)
	/usr/local/go/src/runtime/panic.go:500 +0x1a1
testing.startAlarm.func1()
	/usr/local/go/src/testing/testing.go:918 +0x10b
created by time.goFunc
	/usr/local/go/src/time/sleep.go:154 +0x44

goroutine 1 [chan receive]:
testing.(*T).Run(0xc4200700c0, 0x517b16, 0x1d, 0x522800, 0xc42003bd01)
	/usr/local/go/src/testing/testing.go:647 +0x316
testing.RunTests.func1(0xc4200700c0)
	/usr/local/go/src/testing/testing.go:793 +0x6d
testing.tRunner(0xc4200700c0, 0xc42003be20)
	/usr/local/go/src/testing/testing.go:610 +0x81
testing.RunTests(0x522838, 0x59d100, 0x6, 0x6, 0x514900)
	/usr/local/go/src/testing/testing.go:799 +0x2f5
testing.(*M).Run(0xc42003bee8, 0xc420010510)
	/usr/local/go/src/testing/testing.go:743 +0x85
main.main()
	_/tmp/d20161125-30451-12r8bgf/_test/_testmain.go:66 +0xc6

goroutine 6 [chan receive]:
_/tmp/d20161125-30451-12r8bgf.TestWithConccurentSubscribers(0xc420070180)
	/tmp/d20161125-30451-12r8bgf/solution_test.go:86 +0x1af
testing.tRunner(0xc420070180, 0x522800)
	/usr/local/go/src/testing/testing.go:610 +0x81
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:646 +0x2ec

goroutine 7 [chan receive]:
_/tmp/d20161125-30451-12r8bgf.distributeMessages(0xc42000e420)
	/tmp/d20161125-30451-12r8bgf/solution.go:27 +0x62
created by _/tmp/d20161125-30451-12r8bgf.NewPubSub
	/tmp/d20161125-30451-12r8bgf/solution.go:22 +0xde

goroutine 12 [chan receive]:
_/tmp/d20161125-30451-12r8bgf.TestWithConccurentSubscribers.func1(0xc42000e420, 0xc420054420, 0xc420070180, 0xc4200543c0, 0x4)
	/tmp/d20161125-30451-12r8bgf/solution_test.go:71 +0x114
created by _/tmp/d20161125-30451-12r8bgf.TestWithConccurentSubscribers
	/tmp/d20161125-30451-12r8bgf/solution_test.go:76 +0xe6

goroutine 16 [chan receive]:
_/tmp/d20161125-30451-12r8bgf.TestWithConccurentSubscribers.func1(0xc42000e420, 0xc420054420, 0xc420070180, 0xc4200543c0, 0x8)
	/tmp/d20161125-30451-12r8bgf/solution_test.go:71 +0x114
created by _/tmp/d20161125-30451-12r8bgf.TestWithConccurentSubscribers
	/tmp/d20161125-30451-12r8bgf/solution_test.go:76 +0xe6

goroutine 17 [chan receive]:
_/tmp/d20161125-30451-12r8bgf.TestWithConccurentSubscribers.func1(0xc42000e420, 0xc420054420, 0xc420070180, 0xc4200543c0, 0x9)
	/tmp/d20161125-30451-12r8bgf/solution_test.go:71 +0x114
created by _/tmp/d20161125-30451-12r8bgf.TestWithConccurentSubscribers
	/tmp/d20161125-30451-12r8bgf/solution_test.go:76 +0xe6
exit status 2
FAIL	_/tmp/d20161125-30451-12r8bgf	1.005s
PASS
ok  	_/tmp/d20161125-30451-12r8bgf	0.003s
PASS
ok  	_/tmp/d20161125-30451-12r8bgf	0.053s
Георги Горанов
  • Некоректно
  • 5 успешни тест(а)
  • 1 неуспешни тест(а)
Георги Горанов
package main
type PubSub struct {
in []chan string
}
func NewPubSub() *PubSub {
return &PubSub{make([]chan string, 0)}
}
func (p *PubSub) Subscribe() <-chan string {
ch := make(chan string)
p.in = append(p.in, ch)
return ch
}
func (p *PubSub) Publish() chan<- string {
chOut := make(chan string)
go func() {
message := <-chOut
for _, chIn := range p.in {
chIn <- message
}
}()
return chOut
}
PASS
ok  	_/tmp/d20161125-30451-1fbsdd9	0.003s
PASS
ok  	_/tmp/d20161125-30451-1fbsdd9	0.003s
PASS
ok  	_/tmp/d20161125-30451-1fbsdd9	0.103s
panic: test timed out after 1s

goroutine 537 [running]:
panic(0x4eae20, 0xc420010140)
	/usr/local/go/src/runtime/panic.go:500 +0x1a1
testing.startAlarm.func1()
	/usr/local/go/src/testing/testing.go:918 +0x10b
created by time.goFunc
	/usr/local/go/src/time/sleep.go:154 +0x44

goroutine 1 [chan receive]:
testing.(*T).Run(0xc42007e0c0, 0x517a96, 0x1d, 0x5227c8, 0xc420035d01)
	/usr/local/go/src/testing/testing.go:647 +0x316
testing.RunTests.func1(0xc42007e0c0)
	/usr/local/go/src/testing/testing.go:793 +0x6d
testing.tRunner(0xc42007e0c0, 0xc420035e20)
	/usr/local/go/src/testing/testing.go:610 +0x81
testing.RunTests(0x5227f8, 0x59d100, 0x6, 0x6, 0x514880)
	/usr/local/go/src/testing/testing.go:799 +0x2f5
testing.(*M).Run(0xc420035ee8, 0xc4200563e0)
	/usr/local/go/src/testing/testing.go:743 +0x85
main.main()
	_/tmp/d20161125-30451-1fbsdd9/_test/_testmain.go:66 +0xc6

goroutine 19 [chan receive]:
_/tmp/d20161125-30451-1fbsdd9.TestWithConccurentSubscribers(0xc42007e180)
	/tmp/d20161125-30451-1fbsdd9/solution_test.go:86 +0x23d
testing.tRunner(0xc42007e180, 0x5227c8)
	/usr/local/go/src/testing/testing.go:610 +0x81
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:646 +0x2ec

goroutine 559 [chan receive]:
_/tmp/d20161125-30451-1fbsdd9.TestWithConccurentSubscribers.func1(0xc42006a720, 0xc4200b77a0, 0xc42007e180, 0xc4200b7740, 0x12)
	/tmp/d20161125-30451-1fbsdd9/solution_test.go:71 +0x104
created by _/tmp/d20161125-30451-1fbsdd9.TestWithConccurentSubscribers
	/tmp/d20161125-30451-1fbsdd9/solution_test.go:76 +0x160
exit status 2
FAIL	_/tmp/d20161125-30451-1fbsdd9	1.005s
PASS
ok  	_/tmp/d20161125-30451-1fbsdd9	0.003s
PASS
ok  	_/tmp/d20161125-30451-1fbsdd9	0.053s
Иван Филипов
  • Некоректно
  • 5 успешни тест(а)
  • 1 неуспешни тест(а)
Иван Филипов
package main
type PubSub struct {
Outputs []chan string
}
func NewPubSub() *PubSub {
return &PubSub{make([]chan string, 0)}
}
func (p *PubSub) Subscribe() <-chan string {
NewOne := make(chan string)
p.Outputs = append(p.Outputs, NewOne)
return NewOne
}
func (p *PubSub) Publish() chan<- string {
Input := make(chan string)
go func() {
defer close(Input)
msg := <-Input
for i := range p.Outputs {
p.Outputs[i] <- msg
}
}()
return Input
}
PASS
ok  	_/tmp/d20161125-30451-evtjyi	0.002s
PASS
ok  	_/tmp/d20161125-30451-evtjyi	0.003s
PASS
ok  	_/tmp/d20161125-30451-evtjyi	0.103s
panic: test timed out after 1s

goroutine 48 [running]:
panic(0x4eae40, 0xc420010620)
	/usr/local/go/src/runtime/panic.go:500 +0x1a1
testing.startAlarm.func1()
	/usr/local/go/src/testing/testing.go:918 +0x10b
created by time.goFunc
	/usr/local/go/src/time/sleep.go:154 +0x44

goroutine 1 [chan receive]:
testing.(*T).Run(0xc4200700c0, 0x517ab6, 0x1d, 0x5227e8, 0xc42003bd01)
	/usr/local/go/src/testing/testing.go:647 +0x316
testing.RunTests.func1(0xc4200700c0)
	/usr/local/go/src/testing/testing.go:793 +0x6d
testing.tRunner(0xc4200700c0, 0xc42003be20)
	/usr/local/go/src/testing/testing.go:610 +0x81
testing.RunTests(0x522818, 0x59d100, 0x6, 0x6, 0x5148a0)
	/usr/local/go/src/testing/testing.go:799 +0x2f5
testing.(*M).Run(0xc42003bee8, 0xc420010510)
	/usr/local/go/src/testing/testing.go:743 +0x85
main.main()
	_/tmp/d20161125-30451-evtjyi/_test/_testmain.go:66 +0xc6

goroutine 6 [chan receive]:
_/tmp/d20161125-30451-evtjyi.TestWithConccurentSubscribers(0xc420070180)
	/tmp/d20161125-30451-evtjyi/solution_test.go:86 +0x23d
testing.tRunner(0xc420070180, 0x5227e8)
	/usr/local/go/src/testing/testing.go:610 +0x81
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:646 +0x2ec

goroutine 38 [chan receive]:
_/tmp/d20161125-30451-evtjyi.TestWithConccurentSubscribers.func1(0xc42000e460, 0xc420054c00, 0xc420070180, 0xc420054ba0, 0xa)
	/tmp/d20161125-30451-evtjyi/solution_test.go:71 +0x104
created by _/tmp/d20161125-30451-evtjyi.TestWithConccurentSubscribers
	/tmp/d20161125-30451-evtjyi/solution_test.go:76 +0x160

goroutine 37 [chan receive]:
_/tmp/d20161125-30451-evtjyi.TestWithConccurentSubscribers.func1(0xc42000e460, 0xc420054c00, 0xc420070180, 0xc420054ba0, 0x9)
	/tmp/d20161125-30451-evtjyi/solution_test.go:71 +0x104
created by _/tmp/d20161125-30451-evtjyi.TestWithConccurentSubscribers
	/tmp/d20161125-30451-evtjyi/solution_test.go:76 +0x160

goroutine 46 [chan receive]:
_/tmp/d20161125-30451-evtjyi.TestWithConccurentSubscribers.func1(0xc42000e460, 0xc420054c00, 0xc420070180, 0xc420054ba0, 0x12)
	/tmp/d20161125-30451-evtjyi/solution_test.go:71 +0x104
created by _/tmp/d20161125-30451-evtjyi.TestWithConccurentSubscribers
	/tmp/d20161125-30451-evtjyi/solution_test.go:76 +0x160
exit status 2
FAIL	_/tmp/d20161125-30451-evtjyi	1.005s
PASS
ok  	_/tmp/d20161125-30451-evtjyi	0.003s
PASS
ok  	_/tmp/d20161125-30451-evtjyi	0.053s
Валентин Латунов
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Валентин Латунов
package main
type PubSub struct {
subscribers []chan<- string
pending []chan string
publishChan chan string
done chan struct{}
lock chan struct{}
}
func (p *PubSub) monitorPublish() {
for {
msg := <-p.publishChan
p.lock <- struct{}{}
for _, sub := range p.pending {
p.subscribers = append(p.subscribers, sub)
}
p.pending = nil
<-p.lock
for _, ch := range p.subscribers {
go func(send chan<- string) {
send <- msg
p.done <- struct{}{}
}(ch)
}
for range p.subscribers {
<-p.done
}
}
}
func (p *PubSub) Subscribe() <-chan string {
result := make(chan string)
p.lock <- struct{}{}
p.pending = append(p.pending, result)
<-p.lock
return result
}
func (p *PubSub) Publish() chan<- string {
return p.publishChan
}
func NewPubSub() *PubSub {
result := &PubSub{
publishChan: make(chan string),
done: make(chan struct{}),
lock: make(chan struct{}, 1),
}
go result.monitorPublish()
return result
}
PASS
ok  	_/tmp/d20161125-30451-7tsoen	0.006s
PASS
ok  	_/tmp/d20161125-30451-7tsoen	0.004s
PASS
ok  	_/tmp/d20161125-30451-7tsoen	0.103s
PASS
ok  	_/tmp/d20161125-30451-7tsoen	0.030s
PASS
ok  	_/tmp/d20161125-30451-7tsoen	0.003s
PASS
ok  	_/tmp/d20161125-30451-7tsoen	0.055s
Александър Александров
  • Некоректно
  • 5 успешни тест(а)
  • 1 неуспешни тест(а)
Александър Александров
package main
type PubSub struct {
publisher chan string
subscribers []chan string
}
func NewPubSub() *PubSub {
topic := &PubSub{publisher: make(chan string), subscribers: make([]chan string, 0)}
go func() {
for {
msg := <-topic.publisher
for _, subCh := range topic.subscribers {
subCh <- msg
}
}
}()
return topic
}
func (ps *PubSub) Subscribe() <-chan string {
subCh := make(chan string)
ps.subscribers = append(ps.subscribers, subCh)
return subCh
}
func (ps *PubSub) Publish() chan<- string {
return ps.publisher
}
PASS
ok  	_/tmp/d20161125-30451-18ih2bz	0.003s
PASS
ok  	_/tmp/d20161125-30451-18ih2bz	0.003s
PASS
ok  	_/tmp/d20161125-30451-18ih2bz	0.103s
panic: test timed out after 1s

goroutine 49 [running]:
panic(0x4eae80, 0xc420010620)
	/usr/local/go/src/runtime/panic.go:500 +0x1a1
testing.startAlarm.func1()
	/usr/local/go/src/testing/testing.go:918 +0x10b
created by time.goFunc
	/usr/local/go/src/time/sleep.go:154 +0x44

goroutine 1 [chan receive]:
testing.(*T).Run(0xc4200700c0, 0x517b16, 0x1d, 0x522808, 0xc42003bd01)
	/usr/local/go/src/testing/testing.go:647 +0x316
testing.RunTests.func1(0xc4200700c0)
	/usr/local/go/src/testing/testing.go:793 +0x6d
testing.tRunner(0xc4200700c0, 0xc42003be20)
	/usr/local/go/src/testing/testing.go:610 +0x81
testing.RunTests(0x522838, 0x59d100, 0x6, 0x6, 0x514900)
	/usr/local/go/src/testing/testing.go:799 +0x2f5
testing.(*M).Run(0xc42003bee8, 0xc420010510)
	/usr/local/go/src/testing/testing.go:743 +0x85
main.main()
	_/tmp/d20161125-30451-18ih2bz/_test/_testmain.go:66 +0xc6

goroutine 6 [chan receive]:
_/tmp/d20161125-30451-18ih2bz.TestWithConccurentSubscribers(0xc420070180)
	/tmp/d20161125-30451-18ih2bz/solution_test.go:86 +0x1af
testing.tRunner(0xc420070180, 0x522808)
	/usr/local/go/src/testing/testing.go:610 +0x81
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:646 +0x2ec

goroutine 7 [chan receive]:
_/tmp/d20161125-30451-18ih2bz.NewPubSub.func1(0xc42000e420)
	/tmp/d20161125-30451-18ih2bz/solution.go:12 +0x5a
created by _/tmp/d20161125-30451-18ih2bz.NewPubSub
	/tmp/d20161125-30451-18ih2bz/solution.go:17 +0xf8

goroutine 44 [chan receive]:
_/tmp/d20161125-30451-18ih2bz.TestWithConccurentSubscribers.func1(0xc42000e460, 0xc420054c60, 0xc420070180, 0xc420054c00, 0xf)
	/tmp/d20161125-30451-18ih2bz/solution_test.go:71 +0x114
created by _/tmp/d20161125-30451-18ih2bz.TestWithConccurentSubscribers
	/tmp/d20161125-30451-18ih2bz/solution_test.go:76 +0xe6

goroutine 43 [chan receive]:
_/tmp/d20161125-30451-18ih2bz.TestWithConccurentSubscribers.func1(0xc42000e460, 0xc420054c60, 0xc420070180, 0xc420054c00, 0xe)
	/tmp/d20161125-30451-18ih2bz/solution_test.go:71 +0x114
created by _/tmp/d20161125-30451-18ih2bz.TestWithConccurentSubscribers
	/tmp/d20161125-30451-18ih2bz/solution_test.go:76 +0xe6

goroutine 28 [chan receive]:
_/tmp/d20161125-30451-18ih2bz.NewPubSub.func1(0xc42000e460)
	/tmp/d20161125-30451-18ih2bz/solution.go:12 +0x5a
created by _/tmp/d20161125-30451-18ih2bz.NewPubSub
	/tmp/d20161125-30451-18ih2bz/solution.go:17 +0xf8
exit status 2
FAIL	_/tmp/d20161125-30451-18ih2bz	1.005s
PASS
ok  	_/tmp/d20161125-30451-18ih2bz	0.003s
PASS
ok  	_/tmp/d20161125-30451-18ih2bz	0.053s
Георги Иванов
  • Некоректно
  • 5 успешни тест(а)
  • 1 неуспешни тест(а)
Георги Иванов
package main
type PubSub struct {
subscribers []chan string
}
func (p *PubSub) Subscribe() <-chan string {
c := make(chan string)
p.subscribers = append(p.subscribers, c)
return c
}
func (p *PubSub) Publish() chan<- string {
resultChannel := make(chan string)
go func() {
message := <-resultChannel
for _, ch := range p.subscribers {
ch <- message
}
}()
return resultChannel
}
func NewPubSub() *PubSub {
return &PubSub{subscribers: make([]chan string, 0)}
}
PASS
ok  	_/tmp/d20161125-30451-1g23cuu	0.002s
PASS
ok  	_/tmp/d20161125-30451-1g23cuu	0.003s
PASS
ok  	_/tmp/d20161125-30451-1g23cuu	0.103s
panic: test timed out after 1s

goroutine 2301 [running]:
panic(0x4eae40, 0xc420010900)
	/usr/local/go/src/runtime/panic.go:500 +0x1a1
testing.startAlarm.func1()
	/usr/local/go/src/testing/testing.go:918 +0x10b
created by time.goFunc
	/usr/local/go/src/time/sleep.go:154 +0x44

goroutine 1 [chan receive]:
testing.(*T).Run(0xc4200700c0, 0x517ab6, 0x1d, 0x5227e8, 0xc42003bd01)
	/usr/local/go/src/testing/testing.go:647 +0x316
testing.RunTests.func1(0xc4200700c0)
	/usr/local/go/src/testing/testing.go:793 +0x6d
testing.tRunner(0xc4200700c0, 0xc42003be20)
	/usr/local/go/src/testing/testing.go:610 +0x81
testing.RunTests(0x522818, 0x59d100, 0x6, 0x6, 0x5148a0)
	/usr/local/go/src/testing/testing.go:799 +0x2f5
testing.(*M).Run(0xc42003bee8, 0xc420010510)
	/usr/local/go/src/testing/testing.go:743 +0x85
main.main()
	_/tmp/d20161125-30451-1g23cuu/_test/_testmain.go:66 +0xc6

goroutine 6 [chan receive]:
_/tmp/d20161125-30451-1g23cuu.TestWithConccurentSubscribers(0xc420070180)
	/tmp/d20161125-30451-1g23cuu/solution_test.go:86 +0x23d
testing.tRunner(0xc420070180, 0x5227e8)
	/usr/local/go/src/testing/testing.go:610 +0x81
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:646 +0x2ec

goroutine 2346 [chan receive]:
_/tmp/d20161125-30451-1g23cuu.TestWithConccurentSubscribers.func1(0xc4200af000, 0xc4201201e0, 0xc420070180, 0xc420120180, 0x4)
	/tmp/d20161125-30451-1g23cuu/solution_test.go:71 +0x104
created by _/tmp/d20161125-30451-1g23cuu.TestWithConccurentSubscribers
	/tmp/d20161125-30451-1g23cuu/solution_test.go:76 +0x160

goroutine 2345 [chan receive]:
_/tmp/d20161125-30451-1g23cuu.TestWithConccurentSubscribers.func1(0xc4200af000, 0xc4201201e0, 0xc420070180, 0xc420120180, 0x3)
	/tmp/d20161125-30451-1g23cuu/solution_test.go:71 +0x104
created by _/tmp/d20161125-30451-1g23cuu.TestWithConccurentSubscribers
	/tmp/d20161125-30451-1g23cuu/solution_test.go:76 +0x160

goroutine 2344 [chan receive]:
_/tmp/d20161125-30451-1g23cuu.TestWithConccurentSubscribers.func1(0xc4200af000, 0xc4201201e0, 0xc420070180, 0xc420120180, 0x2)
	/tmp/d20161125-30451-1g23cuu/solution_test.go:71 +0x104
created by _/tmp/d20161125-30451-1g23cuu.TestWithConccurentSubscribers
	/tmp/d20161125-30451-1g23cuu/solution_test.go:76 +0x160

goroutine 2348 [chan receive]:
_/tmp/d20161125-30451-1g23cuu.TestWithConccurentSubscribers.func1(0xc4200af000, 0xc4201201e0, 0xc420070180, 0xc420120180, 0x6)
	/tmp/d20161125-30451-1g23cuu/solution_test.go:71 +0x104
created by _/tmp/d20161125-30451-1g23cuu.TestWithConccurentSubscribers
	/tmp/d20161125-30451-1g23cuu/solution_test.go:76 +0x160

goroutine 2350 [chan receive]:
_/tmp/d20161125-30451-1g23cuu.TestWithConccurentSubscribers.func1(0xc4200af000, 0xc4201201e0, 0xc420070180, 0xc420120180, 0x8)
	/tmp/d20161125-30451-1g23cuu/solution_test.go:71 +0x104
created by _/tmp/d20161125-30451-1g23cuu.TestWithConccurentSubscribers
	/tmp/d20161125-30451-1g23cuu/solution_test.go:76 +0x160

goroutine 2349 [chan receive]:
_/tmp/d20161125-30451-1g23cuu.TestWithConccurentSubscribers.func1(0xc4200af000, 0xc4201201e0, 0xc420070180, 0xc420120180, 0x7)
	/tmp/d20161125-30451-1g23cuu/solution_test.go:71 +0x104
created by _/tmp/d20161125-30451-1g23cuu.TestWithConccurentSubscribers
	/tmp/d20161125-30451-1g23cuu/solution_test.go:76 +0x160

goroutine 2354 [chan receive]:
_/tmp/d20161125-30451-1g23cuu.TestWithConccurentSubscribers.func1(0xc4200af000, 0xc4201201e0, 0xc420070180, 0xc420120180, 0xc)
	/tmp/d20161125-30451-1g23cuu/solution_test.go:71 +0x104
created by _/tmp/d20161125-30451-1g23cuu.TestWithConccurentSubscribers
	/tmp/d20161125-30451-1g23cuu/solution_test.go:76 +0x160

goroutine 2351 [chan receive]:
_/tmp/d20161125-30451-1g23cuu.TestWithConccurentSubscribers.func1(0xc4200af000, 0xc4201201e0, 0xc420070180, 0xc420120180, 0x9)
	/tmp/d20161125-30451-1g23cuu/solution_test.go:71 +0x104
created by _/tmp/d20161125-30451-1g23cuu.TestWithConccurentSubscribers
	/tmp/d20161125-30451-1g23cuu/solution_test.go:76 +0x160

goroutine 2352 [chan receive]:
_/tmp/d20161125-30451-1g23cuu.TestWithConccurentSubscribers.func1(0xc4200af000, 0xc4201201e0, 0xc420070180, 0xc420120180, 0xa)
	/tmp/d20161125-30451-1g23cuu/solution_test.go:71 +0x104
created by _/tmp/d20161125-30451-1g23cuu.TestWithConccurentSubscribers
	/tmp/d20161125-30451-1g23cuu/solution_test.go:76 +0x160

goroutine 2353 [chan receive]:
_/tmp/d20161125-30451-1g23cuu.TestWithConccurentSubscribers.func1(0xc4200af000, 0xc4201201e0, 0xc420070180, 0xc420120180, 0xb)
	/tmp/d20161125-30451-1g23cuu/solution_test.go:71 +0x104
created by _/tmp/d20161125-30451-1g23cuu.TestWithConccurentSubscribers
	/tmp/d20161125-30451-1g23cuu/solution_test.go:76 +0x160

goroutine 2356 [chan receive]:
_/tmp/d20161125-30451-1g23cuu.TestWithConccurentSubscribers.func1(0xc4200af000, 0xc4201201e0, 0xc420070180, 0xc420120180, 0xe)
	/tmp/d20161125-30451-1g23cuu/solution_test.go:71 +0x104
created by _/tmp/d20161125-30451-1g23cuu.TestWithConccurentSubscribers
	/tmp/d20161125-30451-1g23cuu/solution_test.go:76 +0x160

goroutine 2357 [chan receive]:
_/tmp/d20161125-30451-1g23cuu.TestWithConccurentSubscribers.func1(0xc4200af000, 0xc4201201e0, 0xc420070180, 0xc420120180, 0xf)
	/tmp/d20161125-30451-1g23cuu/solution_test.go:71 +0x104
created by _/tmp/d20161125-30451-1g23cuu.TestWithConccurentSubscribers
	/tmp/d20161125-30451-1g23cuu/solution_test.go:76 +0x160

goroutine 2358 [chan receive]:
_/tmp/d20161125-30451-1g23cuu.TestWithConccurentSubscribers.func1(0xc4200af000, 0xc4201201e0, 0xc420070180, 0xc420120180, 0x10)
	/tmp/d20161125-30451-1g23cuu/solution_test.go:71 +0x104
created by _/tmp/d20161125-30451-1g23cuu.TestWithConccurentSubscribers
	/tmp/d20161125-30451-1g23cuu/solution_test.go:76 +0x160

goroutine 2359 [chan receive]:
_/tmp/d20161125-30451-1g23cuu.TestWithConccurentSubscribers.func1(0xc4200af000, 0xc4201201e0, 0xc420070180, 0xc420120180, 0x11)
	/tmp/d20161125-30451-1g23cuu/solution_test.go:71 +0x104
created by _/tmp/d20161125-30451-1g23cuu.TestWithConccurentSubscribers
	/tmp/d20161125-30451-1g23cuu/solution_test.go:76 +0x160

goroutine 2355 [chan receive]:
_/tmp/d20161125-30451-1g23cuu.TestWithConccurentSubscribers.func1(0xc4200af000, 0xc4201201e0, 0xc420070180, 0xc420120180, 0xd)
	/tmp/d20161125-30451-1g23cuu/solution_test.go:71 +0x104
created by _/tmp/d20161125-30451-1g23cuu.TestWithConccurentSubscribers
	/tmp/d20161125-30451-1g23cuu/solution_test.go:76 +0x160

goroutine 2347 [chan receive]:
_/tmp/d20161125-30451-1g23cuu.TestWithConccurentSubscribers.func1(0xc4200af000, 0xc4201201e0, 0xc420070180, 0xc420120180, 0x5)
	/tmp/d20161125-30451-1g23cuu/solution_test.go:71 +0x104
created by _/tmp/d20161125-30451-1g23cuu.TestWithConccurentSubscribers
	/tmp/d20161125-30451-1g23cuu/solution_test.go:76 +0x160

goroutine 2360 [chan receive]:
_/tmp/d20161125-30451-1g23cuu.TestWithConccurentSubscribers.func1(0xc4200af000, 0xc4201201e0, 0xc420070180, 0xc420120180, 0x12)
	/tmp/d20161125-30451-1g23cuu/solution_test.go:71 +0x104
created by _/tmp/d20161125-30451-1g23cuu.TestWithConccurentSubscribers
	/tmp/d20161125-30451-1g23cuu/solution_test.go:76 +0x160

goroutine 2362 [chan send (nil chan)]:
_/tmp/d20161125-30451-1g23cuu.(*PubSub).Publish.func1(0xc4201203c0, 0xc4200af000)
	/tmp/d20161125-30451-1g23cuu/solution.go:18 +0xb9
created by _/tmp/d20161125-30451-1g23cuu.(*PubSub).Publish
	/tmp/d20161125-30451-1g23cuu/solution.go:20 +0x67
exit status 2
FAIL	_/tmp/d20161125-30451-1g23cuu	1.006s
PASS
ok  	_/tmp/d20161125-30451-1g23cuu	0.003s
PASS
ok  	_/tmp/d20161125-30451-1g23cuu	0.054s
Елица Вечнова
  • Некоректно
  • 5 успешни тест(а)
  • 1 неуспешни тест(а)
Елица Вечнова
package main
type PubSub struct {
listenChans []chan string
publishChan chan string
}
func NewPubSub() *PubSub {
listen := make([]chan string, 0)
publish := make(chan string)
p := &PubSub{listenChans: listen, publishChan: publish}
go func(p *PubSub) {
for {
message := <-p.publishChan
for _, listenChan := range p.listenChans {
listenChan <- message
}
}
}(p)
return p
}
func (p *PubSub) Subscribe() <-chan string {
listenerChan := make(chan string)
p.listenChans = append(p.listenChans, listenerChan)
return listenerChan
}
func (p *PubSub) Publish() chan<- string {
return p.publishChan
}
func main() {
}
PASS
ok  	_/tmp/d20161125-30451-1jlrrui	0.002s
PASS
ok  	_/tmp/d20161125-30451-1jlrrui	0.003s
PASS
ok  	_/tmp/d20161125-30451-1jlrrui	0.103s
panic: test timed out after 1s

goroutine 1183 [running]:
panic(0x4eae40, 0xc420010980)
	/usr/local/go/src/runtime/panic.go:500 +0x1a1
testing.startAlarm.func1()
	/usr/local/go/src/testing/testing.go:918 +0x10b
created by time.goFunc
	/usr/local/go/src/time/sleep.go:154 +0x44

goroutine 1 [chan receive]:
testing.(*T).Run(0xc4200700c0, 0x517ad6, 0x1d, 0x522768, 0xc42003bd01)
	/usr/local/go/src/testing/testing.go:647 +0x316
testing.RunTests.func1(0xc4200700c0)
	/usr/local/go/src/testing/testing.go:793 +0x6d
testing.tRunner(0xc4200700c0, 0xc42003be20)
	/usr/local/go/src/testing/testing.go:610 +0x81
testing.RunTests(0x522798, 0x59d100, 0x6, 0x6, 0x5148c0)
	/usr/local/go/src/testing/testing.go:799 +0x2f5
testing.(*M).Run(0xc42003bee8, 0xc420010510)
	/usr/local/go/src/testing/testing.go:743 +0x85
main.main()
	_/tmp/d20161125-30451-1jlrrui/_test/_testmain.go:66 +0xc6

goroutine 6 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.TestWithConccurentSubscribers(0xc420070180)
	/tmp/d20161125-30451-1jlrrui/solution_test.go:86 +0x1b0
testing.tRunner(0xc420070180, 0x522768)
	/usr/local/go/src/testing/testing.go:610 +0x81
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:646 +0x2ec

goroutine 7 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000e420)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 1141 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000f1a0)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 1185 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc4200f8020)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 28 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000e460)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 49 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000e4a0)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 70 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000e4e0)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 91 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000e520)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 112 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000e560)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 133 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000e5a0)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 154 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000e5e0)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 175 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000e620)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 196 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000e660)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 217 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000e6a0)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 238 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000e6e0)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 259 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000e720)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 280 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000e760)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 301 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000e7a0)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 322 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000e7e0)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 343 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000e820)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 364 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000e860)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 385 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000e8a0)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 406 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000e8e0)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 427 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000e920)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 448 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000e960)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 469 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000e9a0)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 490 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000e9e0)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 511 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000ea20)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 532 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000ea60)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 553 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000eaa0)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 574 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000eae0)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 595 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000eb20)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 616 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000eb60)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 637 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000eba0)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 658 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000ebe0)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 679 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000ec20)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 700 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000ec60)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 721 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000eca0)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 742 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000ece0)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 763 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000ed20)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 784 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000ed60)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 805 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000eda0)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 826 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000ede0)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 847 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000ee20)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 868 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000ee60)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 889 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000eea0)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 910 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000eee0)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 931 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000ef20)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 952 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000ef60)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 973 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000efa0)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 994 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000efe0)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 1015 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000f020)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 1036 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000f060)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 1057 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000f0a0)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 1078 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000f0e0)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 1099 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000f120)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 1120 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000f160)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 1220 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.TestWithConccurentSubscribers.func1(0xc4200f8060, 0xc4200e6e40, 0xc420070180, 0xc4200e6de0, 0xd)
	/tmp/d20161125-30451-1jlrrui/solution_test.go:71 +0x104
created by _/tmp/d20161125-30451-1jlrrui.TestWithConccurentSubscribers
	/tmp/d20161125-30451-1jlrrui/solution_test.go:76 +0xe6

goroutine 1206 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc4200f8060)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6

goroutine 1162 [chan receive]:
_/tmp/d20161125-30451-1jlrrui.NewPubSub.func1(0xc42000f1c0)
	/tmp/d20161125-30451-1jlrrui/solution.go:14 +0x5b
created by _/tmp/d20161125-30451-1jlrrui.NewPubSub
	/tmp/d20161125-30451-1jlrrui/solution.go:19 +0xf6
exit status 2
FAIL	_/tmp/d20161125-30451-1jlrrui	1.011s
PASS
ok  	_/tmp/d20161125-30451-1jlrrui	0.003s
PASS
ok  	_/tmp/d20161125-30451-1jlrrui	0.053s
Ралица Великова
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Ралица Великова
package main
type PubSub struct {
subscribers []chan string
subscribersSemaphore chan struct{}
}
func (p *PubSub) init() {
p.subscribers = make([]chan string, 0, 10)
p.subscribersSemaphore = make(chan struct{}, 1)
p.subscribersSemaphore <- struct{}{}
}
func (p *PubSub) Subscribe() <-chan string {
newSubscribeChannel := make(chan string)
<-p.subscribersSemaphore
p.subscribers = append(p.subscribers, newSubscribeChannel)
p.subscribersSemaphore <- struct{}{}
return newSubscribeChannel
}
func (p *PubSub) Publish() chan<- string {
publishChannel := make(chan string)
go func() {
message := <-publishChannel
<-p.subscribersSemaphore
for _, subscriber := range p.subscribers {
subscriber <- message
}
p.subscribersSemaphore <- struct{}{}
}()
return publishChannel
}
func NewPubSub() *PubSub {
var newPubSub PubSub
newPubSub.init()
return &newPubSub
}
PASS
ok  	_/tmp/d20161125-30451-1nvl1a7	0.002s
PASS
ok  	_/tmp/d20161125-30451-1nvl1a7	0.003s
PASS
ok  	_/tmp/d20161125-30451-1nvl1a7	0.103s
PASS
ok  	_/tmp/d20161125-30451-1nvl1a7	0.019s
PASS
ok  	_/tmp/d20161125-30451-1nvl1a7	0.003s
PASS
ok  	_/tmp/d20161125-30451-1nvl1a7	0.053s
Николай Генов
  • Некоректно
  • 4 успешни тест(а)
  • 2 неуспешни тест(а)
Николай Генов
package main
type PubSub struct {
subs []chan string
}
func (ps *PubSub) Subscribe() <-chan string {
ch := make(chan string)
ps.subs = append(ps.subs, ch)
return ch
}
func (ps *PubSub) Publish() chan<- string {
ch := make(chan string)
go func() {
msg := <-ch
for _, sub := range ps.subs {
sub <- msg
}
}()
return ch
}
func NewPubSub() *PubSub {
return &PubSub{make([]chan string, 0)}
}
PASS
ok  	_/tmp/d20161125-30451-9gqksy	0.003s
PASS
ok  	_/tmp/d20161125-30451-9gqksy	0.003s
PASS
ok  	_/tmp/d20161125-30451-9gqksy	0.103s
panic: test timed out after 1s

goroutine 33 [running]:
panic(0x4eae40, 0xc4200aa010)
	/usr/local/go/src/runtime/panic.go:500 +0x1a1
testing.startAlarm.func1()
	/usr/local/go/src/testing/testing.go:918 +0x10b
created by time.goFunc
	/usr/local/go/src/time/sleep.go:154 +0x44

goroutine 1 [chan receive]:
testing.(*T).Run(0xc4200700c0, 0x517ab6, 0x1d, 0x5227e8, 0xc42003bd01)
	/usr/local/go/src/testing/testing.go:647 +0x316
testing.RunTests.func1(0xc4200700c0)
	/usr/local/go/src/testing/testing.go:793 +0x6d
testing.tRunner(0xc4200700c0, 0xc42003be20)
	/usr/local/go/src/testing/testing.go:610 +0x81
testing.RunTests(0x522818, 0x59d100, 0x6, 0x6, 0x5148a0)
	/usr/local/go/src/testing/testing.go:799 +0x2f5
testing.(*M).Run(0xc42003bee8, 0xc420010510)
	/usr/local/go/src/testing/testing.go:743 +0x85
main.main()
	_/tmp/d20161125-30451-9gqksy/_test/_testmain.go:66 +0xc6

goroutine 6 [chan receive]:
_/tmp/d20161125-30451-9gqksy.TestWithConccurentSubscribers(0xc420070180)
	/tmp/d20161125-30451-9gqksy/solution_test.go:86 +0x23d
testing.tRunner(0xc420070180, 0x5227e8)
	/usr/local/go/src/testing/testing.go:610 +0x81
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:646 +0x2ec

goroutine 10 [chan receive]:
_/tmp/d20161125-30451-9gqksy.TestWithConccurentSubscribers.func1(0xc42000e420, 0xc4200543c0, 0xc420070180, 0xc420054360, 0x3)
	/tmp/d20161125-30451-9gqksy/solution_test.go:71 +0x104
created by _/tmp/d20161125-30451-9gqksy.TestWithConccurentSubscribers
	/tmp/d20161125-30451-9gqksy/solution_test.go:76 +0x160

goroutine 15 [chan receive]:
_/tmp/d20161125-30451-9gqksy.TestWithConccurentSubscribers.func1(0xc42000e420, 0xc4200543c0, 0xc420070180, 0xc420054360, 0x8)
	/tmp/d20161125-30451-9gqksy/solution_test.go:71 +0x104
created by _/tmp/d20161125-30451-9gqksy.TestWithConccurentSubscribers
	/tmp/d20161125-30451-9gqksy/solution_test.go:76 +0x160

goroutine 18 [chan receive]:
_/tmp/d20161125-30451-9gqksy.TestWithConccurentSubscribers.func1(0xc42000e420, 0xc4200543c0, 0xc420070180, 0xc420054360, 0xb)
	/tmp/d20161125-30451-9gqksy/solution_test.go:71 +0x104
created by _/tmp/d20161125-30451-9gqksy.TestWithConccurentSubscribers
	/tmp/d20161125-30451-9gqksy/solution_test.go:76 +0x160
exit status 2
FAIL	_/tmp/d20161125-30451-9gqksy	1.005s
--- FAIL: TestMultipleMessagesOneSubscriber (0.00s)
	solution_test.go:105: Expected to recieve NaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNa, but recieved NaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNa.
FAIL
exit status 1
FAIL	_/tmp/d20161125-30451-9gqksy	0.003s
PASS
ok  	_/tmp/d20161125-30451-9gqksy	0.053s
Емил Дудев
  • Некоректно
  • 5 успешни тест(а)
  • 1 неуспешни тест(а)
Емил Дудев
package main
type PubSub struct {
subscribers []chan string
queue chan string
}
func NewPubSub() (r *PubSub) {
r = &PubSub{
subscribers: make([]chan string, 0),
queue: make(chan string),
}
go func() {
for str := range r.queue {
for _, s := range r.subscribers {
s <- str
}
}
}()
return
}
func (p *PubSub) Subscribe() (c chan string) {
c = make(chan string)
p.subscribers = append(p.subscribers, c)
return
}
func (p *PubSub) Publish() chan string {
return p.queue
}
PASS
ok  	_/tmp/d20161125-30451-5qt2tb	0.002s
PASS
ok  	_/tmp/d20161125-30451-5qt2tb	0.003s
PASS
ok  	_/tmp/d20161125-30451-5qt2tb	0.103s
panic: test timed out after 1s

goroutine 28 [running]:
panic(0x4eade0, 0xc420010610)
	/usr/local/go/src/runtime/panic.go:500 +0x1a1
testing.startAlarm.func1()
	/usr/local/go/src/testing/testing.go:918 +0x10b
created by time.goFunc
	/usr/local/go/src/time/sleep.go:154 +0x44

goroutine 1 [chan receive]:
testing.(*T).Run(0xc4200700c0, 0x517a76, 0x1d, 0x522728, 0xc42003bd01)
	/usr/local/go/src/testing/testing.go:647 +0x316
testing.RunTests.func1(0xc4200700c0)
	/usr/local/go/src/testing/testing.go:793 +0x6d
testing.tRunner(0xc4200700c0, 0xc42003be20)
	/usr/local/go/src/testing/testing.go:610 +0x81
testing.RunTests(0x522758, 0x59d100, 0x6, 0x6, 0x514860)
	/usr/local/go/src/testing/testing.go:799 +0x2f5
testing.(*M).Run(0xc42003bee8, 0xc420010510)
	/usr/local/go/src/testing/testing.go:743 +0x85
main.main()
	_/tmp/d20161125-30451-5qt2tb/_test/_testmain.go:66 +0xc6

goroutine 6 [chan receive]:
_/tmp/d20161125-30451-5qt2tb.TestWithConccurentSubscribers(0xc420070180)
	/tmp/d20161125-30451-5qt2tb/solution_test.go:86 +0x1b0
testing.tRunner(0xc420070180, 0x522728)
	/usr/local/go/src/testing/testing.go:610 +0x81
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:646 +0x2ec

goroutine 7 [chan receive]:
_/tmp/d20161125-30451-5qt2tb.NewPubSub.func1(0xc420028040)
	/tmp/d20161125-30451-5qt2tb/solution.go:15 +0x66
created by _/tmp/d20161125-30451-5qt2tb.NewPubSub
	/tmp/d20161125-30451-5qt2tb/solution.go:20 +0x12d

goroutine 12 [chan receive]:
_/tmp/d20161125-30451-5qt2tb.TestWithConccurentSubscribers.func1(0xc42000e420, 0xc420054420, 0xc420070180, 0xc4200543c0, 0x4)
	/tmp/d20161125-30451-5qt2tb/solution_test.go:71 +0x104
created by _/tmp/d20161125-30451-5qt2tb.TestWithConccurentSubscribers
	/tmp/d20161125-30451-5qt2tb/solution_test.go:76 +0xe6

goroutine 13 [chan receive]:
_/tmp/d20161125-30451-5qt2tb.TestWithConccurentSubscribers.func1(0xc42000e420, 0xc420054420, 0xc420070180, 0xc4200543c0, 0x5)
	/tmp/d20161125-30451-5qt2tb/solution_test.go:71 +0x104
created by _/tmp/d20161125-30451-5qt2tb.TestWithConccurentSubscribers
	/tmp/d20161125-30451-5qt2tb/solution_test.go:76 +0xe6

goroutine 14 [chan receive]:
_/tmp/d20161125-30451-5qt2tb.TestWithConccurentSubscribers.func1(0xc42000e420, 0xc420054420, 0xc420070180, 0xc4200543c0, 0x6)
	/tmp/d20161125-30451-5qt2tb/solution_test.go:71 +0x104
created by _/tmp/d20161125-30451-5qt2tb.TestWithConccurentSubscribers
	/tmp/d20161125-30451-5qt2tb/solution_test.go:76 +0xe6

goroutine 15 [chan receive]:
_/tmp/d20161125-30451-5qt2tb.TestWithConccurentSubscribers.func1(0xc42000e420, 0xc420054420, 0xc420070180, 0xc4200543c0, 0x7)
	/tmp/d20161125-30451-5qt2tb/solution_test.go:71 +0x104
created by _/tmp/d20161125-30451-5qt2tb.TestWithConccurentSubscribers
	/tmp/d20161125-30451-5qt2tb/solution_test.go:76 +0xe6

goroutine 16 [chan receive]:
_/tmp/d20161125-30451-5qt2tb.TestWithConccurentSubscribers.func1(0xc42000e420, 0xc420054420, 0xc420070180, 0xc4200543c0, 0x8)
	/tmp/d20161125-30451-5qt2tb/solution_test.go:71 +0x104
created by _/tmp/d20161125-30451-5qt2tb.TestWithConccurentSubscribers
	/tmp/d20161125-30451-5qt2tb/solution_test.go:76 +0xe6

goroutine 27 [chan receive]:
_/tmp/d20161125-30451-5qt2tb.TestWithConccurentSubscribers.func1(0xc42000e420, 0xc420054420, 0xc420070180, 0xc4200543c0, 0x13)
	/tmp/d20161125-30451-5qt2tb/solution_test.go:71 +0x104
created by _/tmp/d20161125-30451-5qt2tb.TestWithConccurentSubscribers
	/tmp/d20161125-30451-5qt2tb/solution_test.go:76 +0xe6
exit status 2
FAIL	_/tmp/d20161125-30451-5qt2tb	1.005s
PASS
ok  	_/tmp/d20161125-30451-5qt2tb	0.003s
PASS
ok  	_/tmp/d20161125-30451-5qt2tb	0.053s
Диан Тодоров
  • Некоректно
  • 5 успешни тест(а)
  • 1 неуспешни тест(а)
Диан Тодоров
package main
// PubSub is publish subscribe pattern implementation
type PubSub struct {
subscribers []chan string
publisher chan string
ban chan int
}
// NewPubSub is a constructor for PubSub. It also starts a goroutine for managing the publish of events
func NewPubSub() *PubSub {
ps := PubSub{
subscribers: make([]chan string, 0),
publisher: make(chan string),
ban: make(chan int),
}
go ps.start()
return &ps
}
func (ps *PubSub) start() {
for {
subs := ps.subscribers
m := <-ps.publisher
for _, s := range subs {
s <- m
}
}
}
// Publish an event to the PubSub for consumption from the subscribers
func (ps *PubSub) Publish() chan<- string {
return ps.publisher
}
// Subscribe to a PubSub for receiving events.
func (ps *PubSub) Subscribe() <-chan string {
c := make(chan string)
ps.subscribers = append(ps.subscribers, c)
return c
}
PASS
ok  	_/tmp/d20161125-30451-308q4u	0.003s
PASS
ok  	_/tmp/d20161125-30451-308q4u	0.003s
PASS
ok  	_/tmp/d20161125-30451-308q4u	0.103s
panic: test timed out after 1s

goroutine 33 [running]:
panic(0x4eae60, 0xc4200aa010)
	/usr/local/go/src/runtime/panic.go:500 +0x1a1
testing.startAlarm.func1()
	/usr/local/go/src/testing/testing.go:918 +0x10b
created by time.goFunc
	/usr/local/go/src/time/sleep.go:154 +0x44

goroutine 1 [chan receive]:
testing.(*T).Run(0xc4200700c0, 0x517b16, 0x1d, 0x5227a8, 0xc420035d01)
	/usr/local/go/src/testing/testing.go:647 +0x316
testing.RunTests.func1(0xc4200700c0)
	/usr/local/go/src/testing/testing.go:793 +0x6d
testing.tRunner(0xc4200700c0, 0xc420035e20)
	/usr/local/go/src/testing/testing.go:610 +0x81
testing.RunTests(0x5227d8, 0x59d100, 0x6, 0x6, 0x514900)
	/usr/local/go/src/testing/testing.go:799 +0x2f5
testing.(*M).Run(0xc420035ee8, 0xc420010510)
	/usr/local/go/src/testing/testing.go:743 +0x85
main.main()
	_/tmp/d20161125-30451-308q4u/_test/_testmain.go:66 +0xc6

goroutine 6 [chan receive]:
_/tmp/d20161125-30451-308q4u.TestWithConccurentSubscribers(0xc420070180)
	/tmp/d20161125-30451-308q4u/solution_test.go:86 +0x1b0
testing.tRunner(0xc420070180, 0x5227a8)
	/usr/local/go/src/testing/testing.go:610 +0x81
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:646 +0x2ec

goroutine 7 [chan receive]:
_/tmp/d20161125-30451-308q4u.(*PubSub).start(0xc42000a480)
	/tmp/d20161125-30451-308q4u/solution.go:24 +0x6c
created by _/tmp/d20161125-30451-308q4u.NewPubSub
	/tmp/d20161125-30451-308q4u/solution.go:17 +0x176

goroutine 8 [chan receive]:
_/tmp/d20161125-30451-308q4u.TestWithConccurentSubscribers.func1(0xc42000a480, 0xc420054480, 0xc420070180, 0xc420054420, 0x0)
	/tmp/d20161125-30451-308q4u/solution_test.go:71 +0x104
created by _/tmp/d20161125-30451-308q4u.TestWithConccurentSubscribers
	/tmp/d20161125-30451-308q4u/solution_test.go:76 +0xe6

goroutine 9 [chan receive]:
_/tmp/d20161125-30451-308q4u.TestWithConccurentSubscribers.func1(0xc42000a480, 0xc420054480, 0xc420070180, 0xc420054420, 0x1)
	/tmp/d20161125-30451-308q4u/solution_test.go:71 +0x104
created by _/tmp/d20161125-30451-308q4u.TestWithConccurentSubscribers
	/tmp/d20161125-30451-308q4u/solution_test.go:76 +0xe6

goroutine 10 [chan receive]:
_/tmp/d20161125-30451-308q4u.TestWithConccurentSubscribers.func1(0xc42000a480, 0xc420054480, 0xc420070180, 0xc420054420, 0x2)
	/tmp/d20161125-30451-308q4u/solution_test.go:71 +0x104
created by _/tmp/d20161125-30451-308q4u.TestWithConccurentSubscribers
	/tmp/d20161125-30451-308q4u/solution_test.go:76 +0xe6

goroutine 11 [chan receive]:
_/tmp/d20161125-30451-308q4u.TestWithConccurentSubscribers.func1(0xc42000a480, 0xc420054480, 0xc420070180, 0xc420054420, 0x3)
	/tmp/d20161125-30451-308q4u/solution_test.go:71 +0x104
created by _/tmp/d20161125-30451-308q4u.TestWithConccurentSubscribers
	/tmp/d20161125-30451-308q4u/solution_test.go:76 +0xe6

goroutine 12 [chan receive]:
_/tmp/d20161125-30451-308q4u.TestWithConccurentSubscribers.func1(0xc42000a480, 0xc420054480, 0xc420070180, 0xc420054420, 0x4)
	/tmp/d20161125-30451-308q4u/solution_test.go:71 +0x104
created by _/tmp/d20161125-30451-308q4u.TestWithConccurentSubscribers
	/tmp/d20161125-30451-308q4u/solution_test.go:76 +0xe6

goroutine 13 [chan receive]:
_/tmp/d20161125-30451-308q4u.TestWithConccurentSubscribers.func1(0xc42000a480, 0xc420054480, 0xc420070180, 0xc420054420, 0x5)
	/tmp/d20161125-30451-308q4u/solution_test.go:71 +0x104
created by _/tmp/d20161125-30451-308q4u.TestWithConccurentSubscribers
	/tmp/d20161125-30451-308q4u/solution_test.go:76 +0xe6

goroutine 16 [chan receive]:
_/tmp/d20161125-30451-308q4u.TestWithConccurentSubscribers.func1(0xc42000a480, 0xc420054480, 0xc420070180, 0xc420054420, 0x8)
	/tmp/d20161125-30451-308q4u/solution_test.go:71 +0x104
created by _/tmp/d20161125-30451-308q4u.TestWithConccurentSubscribers
	/tmp/d20161125-30451-308q4u/solution_test.go:76 +0xe6

goroutine 17 [chan receive]:
_/tmp/d20161125-30451-308q4u.TestWithConccurentSubscribers.func1(0xc42000a480, 0xc420054480, 0xc420070180, 0xc420054420, 0x9)
	/tmp/d20161125-30451-308q4u/solution_test.go:71 +0x104
created by _/tmp/d20161125-30451-308q4u.TestWithConccurentSubscribers
	/tmp/d20161125-30451-308q4u/solution_test.go:76 +0xe6

goroutine 18 [chan receive]:
_/tmp/d20161125-30451-308q4u.TestWithConccurentSubscribers.func1(0xc42000a480, 0xc420054480, 0xc420070180, 0xc420054420, 0xa)
	/tmp/d20161125-30451-308q4u/solution_test.go:71 +0x104
created by _/tmp/d20161125-30451-308q4u.TestWithConccurentSubscribers
	/tmp/d20161125-30451-308q4u/solution_test.go:76 +0xe6

goroutine 23 [chan receive]:
_/tmp/d20161125-30451-308q4u.TestWithConccurentSubscribers.func1(0xc42000a480, 0xc420054480, 0xc420070180, 0xc420054420, 0xf)
	/tmp/d20161125-30451-308q4u/solution_test.go:71 +0x104
created by _/tmp/d20161125-30451-308q4u.TestWithConccurentSubscribers
	/tmp/d20161125-30451-308q4u/solution_test.go:76 +0xe6

goroutine 24 [chan receive]:
_/tmp/d20161125-30451-308q4u.TestWithConccurentSubscribers.func1(0xc42000a480, 0xc420054480, 0xc420070180, 0xc420054420, 0x10)
	/tmp/d20161125-30451-308q4u/solution_test.go:71 +0x104
created by _/tmp/d20161125-30451-308q4u.TestWithConccurentSubscribers
	/tmp/d20161125-30451-308q4u/solution_test.go:76 +0xe6

goroutine 25 [chan receive]:
_/tmp/d20161125-30451-308q4u.TestWithConccurentSubscribers.func1(0xc42000a480, 0xc420054480, 0xc420070180, 0xc420054420, 0x11)
	/tmp/d20161125-30451-308q4u/solution_test.go:71 +0x104
created by _/tmp/d20161125-30451-308q4u.TestWithConccurentSubscribers
	/tmp/d20161125-30451-308q4u/solution_test.go:76 +0xe6

goroutine 26 [chan receive]:
_/tmp/d20161125-30451-308q4u.TestWithConccurentSubscribers.func1(0xc42000a480, 0xc420054480, 0xc420070180, 0xc420054420, 0x12)
	/tmp/d20161125-30451-308q4u/solution_test.go:71 +0x104
created by _/tmp/d20161125-30451-308q4u.TestWithConccurentSubscribers
	/tmp/d20161125-30451-308q4u/solution_test.go:76 +0xe6
exit status 2
FAIL	_/tmp/d20161125-30451-308q4u	1.006s
PASS
ok  	_/tmp/d20161125-30451-308q4u	0.003s
PASS
ok  	_/tmp/d20161125-30451-308q4u	0.053s
Данислав Киров
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Данислав Киров
package main
type PubSub struct {
subscribers []chan string
publishers []chan string
syncChan chan struct{}
}
func (p *PubSub) Subscribe() <-chan string {
<-p.syncChan
ch := make(chan string)
p.subscribers = append(p.subscribers, ch)
p.syncChan <- struct{}{}
return ch
}
func (p *PubSub) Publish() chan<- string {
ch := make(chan string)
p.publishers = append(p.publishers, ch)
go listen(p, ch)
return ch
}
func listen(p *PubSub, ch chan string) {
for str := range ch {
<-p.syncChan
for _, channel := range p.subscribers {
channel <- str
}
p.syncChan <- struct{}{}
}
}
func NewPubSub() *PubSub {
p := new(PubSub)
p.syncChan = make(chan struct{}, 1)
p.syncChan <- struct{}{}
return p
}
PASS
ok  	_/tmp/d20161125-30451-fjckwd	0.003s
PASS
ok  	_/tmp/d20161125-30451-fjckwd	0.003s
PASS
ok  	_/tmp/d20161125-30451-fjckwd	0.103s
PASS
ok  	_/tmp/d20161125-30451-fjckwd	0.021s
PASS
ok  	_/tmp/d20161125-30451-fjckwd	0.003s
PASS
ok  	_/tmp/d20161125-30451-fjckwd	0.054s
Теодора Иванова
  • Некоректно
  • 1 успешни тест(а)
  • 5 неуспешни тест(а)
Теодора Иванова
package main
import (
"fmt"
)
// array for subscribers in publish check if free return pub
type PubSub struct {
message string
person []chan string
index int
}
func NewPubSub() *PubSub {
ps := new(PubSub)
ps.message = ""
ps.person = make([]chan string, 0)
ps.person = append(ps.person, make(chan string))
ps.index = 0
return ps
}
func (ps *PubSub) Subscribe() <-chan string {
ps.person = append(ps.person, make(chan string))
return ps.person[ps.index]
}
func (ps *PubSub) Publish() chan<- string {
index := 0
ps.index = 0
for i := range ps.person {
select {
case _, ok := <-ps.person[i]:
{
if ok {
index++
}
}
default:
index++
}
}
if index == (len(ps.person)) {
ps.index++
return ps.person[0]
}
return make(chan string)
}
func main() {
ps := NewPubSub()
a := ps.Subscribe()
b := ps.Subscribe()
c := ps.Subscribe()
go func() {
ps.Publish() <- "wat"
ps.Publish() <- "wat"
ps.Publish() <- "wat"
ps.Publish() <- "wat"
ps.Publish() <- "wat"
ps.Publish() <- "wat"
}()
fmt.Printf("A recieved %s, B recieved %s and we ignore C!\n", <-a, <-b)
fmt.Printf("A recieved %s, B recieved %s and C received %s\n", <-a, <-b, <-c)
}
panic: test timed out after 1s

goroutine 7 [running]:
panic(0x4ebe40, 0xc4200105e0)
	/usr/local/go/src/runtime/panic.go:500 +0x1a1
testing.startAlarm.func1()
	/usr/local/go/src/testing/testing.go:918 +0x10b
created by time.goFunc
	/usr/local/go/src/time/sleep.go:154 +0x44

goroutine 1 [chan receive]:
testing.(*T).Run(0xc4200700c0, 0x51740e, 0x16, 0x523888, 0xc42003bd30)
	/usr/local/go/src/testing/testing.go:647 +0x316
testing.RunTests.func1(0xc4200700c0)
	/usr/local/go/src/testing/testing.go:793 +0x6d
testing.tRunner(0xc4200700c0, 0xc42003be20)
	/usr/local/go/src/testing/testing.go:610 +0x81
testing.RunTests(0x5238b0, 0x59e100, 0x6, 0x6, 0x5158e0)
	/usr/local/go/src/testing/testing.go:799 +0x2f5
testing.(*M).Run(0xc42003bee8, 0xc420010510)
	/usr/local/go/src/testing/testing.go:743 +0x85
main.main()
	_/tmp/d20161125-30451-oogwf1/_test/_testmain.go:66 +0xc6

goroutine 6 [chan send]:
_/tmp/d20161125-30451-oogwf1.TestWithTwoSubscribers(0xc420070180)
	/tmp/d20161125-30451-oogwf1/solution_test.go:30 +0x2bd
testing.tRunner(0xc420070180, 0x523888)
	/usr/local/go/src/testing/testing.go:610 +0x81
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:646 +0x2ec
exit status 2
FAIL	_/tmp/d20161125-30451-oogwf1	1.005s
panic: test timed out after 1s

goroutine 7 [running]:
panic(0x4ebe40, 0xc4200105e0)
	/usr/local/go/src/runtime/panic.go:500 +0x1a1
testing.startAlarm.func1()
	/usr/local/go/src/testing/testing.go:918 +0x10b
created by time.goFunc
	/usr/local/go/src/time/sleep.go:154 +0x44

goroutine 1 [chan receive]:
testing.(*T).Run(0xc4200700c0, 0x51a672, 0x26, 0x523870, 0xc420035d01)
	/usr/local/go/src/testing/testing.go:647 +0x316
testing.RunTests.func1(0xc4200700c0)
	/usr/local/go/src/testing/testing.go:793 +0x6d
testing.tRunner(0xc4200700c0, 0xc420035e20)
	/usr/local/go/src/testing/testing.go:610 +0x81
testing.RunTests(0x5238b0, 0x59e100, 0x6, 0x6, 0x5158e0)
	/usr/local/go/src/testing/testing.go:799 +0x2f5
testing.(*M).Run(0xc420035ee8, 0xc420010510)
	/usr/local/go/src/testing/testing.go:743 +0x85
main.main()
	_/tmp/d20161125-30451-oogwf1/_test/_testmain.go:66 +0xc6

goroutine 6 [chan send]:
_/tmp/d20161125-30451-oogwf1.TestMultipleMessagesWithoutSubscribers(0xc420070180)
	/tmp/d20161125-30451-oogwf1/solution_test.go:43 +0x17c
testing.tRunner(0xc420070180, 0x523870)
	/usr/local/go/src/testing/testing.go:610 +0x81
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:646 +0x2ec
exit status 2
FAIL	_/tmp/d20161125-30451-oogwf1	1.005s
panic: test timed out after 1s

goroutine 17 [running]:
panic(0x4ebe40, 0xc42008e010)
	/usr/local/go/src/runtime/panic.go:500 +0x1a1
testing.startAlarm.func1()
	/usr/local/go/src/testing/testing.go:918 +0x10b
created by time.goFunc
	/usr/local/go/src/time/sleep.go:154 +0x44

goroutine 1 [chan receive]:
testing.(*T).Run(0xc4200720c0, 0x5165c0, 0x12, 0x523858, 0xc42003bd01)
	/usr/local/go/src/testing/testing.go:647 +0x316
testing.RunTests.func1(0xc4200720c0)
	/usr/local/go/src/testing/testing.go:793 +0x6d
testing.tRunner(0xc4200720c0, 0xc42003be20)
	/usr/local/go/src/testing/testing.go:610 +0x81
testing.RunTests(0x5238b0, 0x59e100, 0x6, 0x6, 0x5158e0)
	/usr/local/go/src/testing/testing.go:799 +0x2f5
testing.(*M).Run(0xc42003bee8, 0xc420010510)
	/usr/local/go/src/testing/testing.go:743 +0x85
main.main()
	_/tmp/d20161125-30451-oogwf1/_test/_testmain.go:66 +0xc6

goroutine 6 [chan send]:
_/tmp/d20161125-30451-oogwf1.TestLateSubscriber(0xc420072180)
	/tmp/d20161125-30451-oogwf1/solution_test.go:49 +0x18d
testing.tRunner(0xc420072180, 0x523858)
	/usr/local/go/src/testing/testing.go:610 +0x81
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:646 +0x2ec
exit status 2
FAIL	_/tmp/d20161125-30451-oogwf1	1.005s
panic: test timed out after 1s

goroutine 27 [running]:
panic(0x4ebe40, 0xc420010600)
	/usr/local/go/src/runtime/panic.go:500 +0x1a1
testing.startAlarm.func1()
	/usr/local/go/src/testing/testing.go:918 +0x10b
created by time.goFunc
	/usr/local/go/src/time/sleep.go:154 +0x44

goroutine 1 [chan receive]:
testing.(*T).Run(0xc4200700c0, 0x518af6, 0x1d, 0x523880, 0xc42003bd01)
	/usr/local/go/src/testing/testing.go:647 +0x316
testing.RunTests.func1(0xc4200700c0)
	/usr/local/go/src/testing/testing.go:793 +0x6d
testing.tRunner(0xc4200700c0, 0xc42003be20)
	/usr/local/go/src/testing/testing.go:610 +0x81
testing.RunTests(0x5238b0, 0x59e100, 0x6, 0x6, 0x5158e0)
	/usr/local/go/src/testing/testing.go:799 +0x2f5
testing.(*M).Run(0xc42003bee8, 0xc420010510)
	/usr/local/go/src/testing/testing.go:743 +0x85
main.main()
	_/tmp/d20161125-30451-oogwf1/_test/_testmain.go:66 +0xc6

goroutine 6 [chan receive]:
_/tmp/d20161125-30451-oogwf1.TestWithConccurentSubscribers(0xc420070180)
	/tmp/d20161125-30451-oogwf1/solution_test.go:86 +0x2a5
testing.tRunner(0xc420070180, 0x523880)
	/usr/local/go/src/testing/testing.go:610 +0x81
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:646 +0x2ec

goroutine 8 [chan receive]:
_/tmp/d20161125-30451-oogwf1.TestWithConccurentSubscribers.func1(0xc42000a480, 0xc420054420, 0xc420070180, 0xc4200543c0, 0x1)
	/tmp/d20161125-30451-oogwf1/solution_test.go:71 +0x132
created by _/tmp/d20161125-30451-oogwf1.TestWithConccurentSubscribers
	/tmp/d20161125-30451-oogwf1/solution_test.go:76 +0x1c8

goroutine 9 [chan receive]:
_/tmp/d20161125-30451-oogwf1.TestWithConccurentSubscribers.func1(0xc42000a480, 0xc420054420, 0xc420070180, 0xc4200543c0, 0x2)
	/tmp/d20161125-30451-oogwf1/solution_test.go:71 +0x132
created by _/tmp/d20161125-30451-oogwf1.TestWithConccurentSubscribers
	/tmp/d20161125-30451-oogwf1/solution_test.go:76 +0x1c8

goroutine 10 [chan receive]:
_/tmp/d20161125-30451-oogwf1.TestWithConccurentSubscribers.func1(0xc42000a480, 0xc420054420, 0xc420070180, 0xc4200543c0, 0x3)
	/tmp/d20161125-30451-oogwf1/solution_test.go:71 +0x132
created by _/tmp/d20161125-30451-oogwf1.TestWithConccurentSubscribers
	/tmp/d20161125-30451-oogwf1/solution_test.go:76 +0x1c8

goroutine 11 [chan receive]:
_/tmp/d20161125-30451-oogwf1.TestWithConccurentSubscribers.func1(0xc42000a480, 0xc420054420, 0xc420070180, 0xc4200543c0, 0x4)
	/tmp/d20161125-30451-oogwf1/solution_test.go:71 +0x132
created by _/tmp/d20161125-30451-oogwf1.TestWithConccurentSubscribers
	/tmp/d20161125-30451-oogwf1/solution_test.go:76 +0x1c8

goroutine 12 [chan receive]:
_/tmp/d20161125-30451-oogwf1.TestWithConccurentSubscribers.func1(0xc42000a480, 0xc420054420, 0xc420070180, 0xc4200543c0, 0x5)
	/tmp/d20161125-30451-oogwf1/solution_test.go:71 +0x132
created by _/tmp/d20161125-30451-oogwf1.TestWithConccurentSubscribers
	/tmp/d20161125-30451-oogwf1/solution_test.go:76 +0x1c8

goroutine 13 [chan receive]:
_/tmp/d20161125-30451-oogwf1.TestWithConccurentSubscribers.func1(0xc42000a480, 0xc420054420, 0xc420070180, 0xc4200543c0, 0x6)
	/tmp/d20161125-30451-oogwf1/solution_test.go:71 +0x132
created by _/tmp/d20161125-30451-oogwf1.TestWithConccurentSubscribers
	/tmp/d20161125-30451-oogwf1/solution_test.go:76 +0x1c8

goroutine 14 [chan receive]:
_/tmp/d20161125-30451-oogwf1.TestWithConccurentSubscribers.func1(0xc42000a480, 0xc420054420, 0xc420070180, 0xc4200543c0, 0x7)
	/tmp/d20161125-30451-oogwf1/solution_test.go:71 +0x132
created by _/tmp/d20161125-30451-oogwf1.TestWithConccurentSubscribers
	/tmp/d20161125-30451-oogwf1/solution_test.go:76 +0x1c8

goroutine 15 [chan receive]:
_/tmp/d20161125-30451-oogwf1.TestWithConccurentSubscribers.func1(0xc42000a480, 0xc420054420, 0xc420070180, 0xc4200543c0, 0x8)
	/tmp/d20161125-30451-oogwf1/solution_test.go:71 +0x132
created by _/tmp/d20161125-30451-oogwf1.TestWithConccurentSubscribers
	/tmp/d20161125-30451-oogwf1/solution_test.go:76 +0x1c8

goroutine 16 [chan receive]:
_/tmp/d20161125-30451-oogwf1.TestWithConccurentSubscribers.func1(0xc42000a480, 0xc420054420, 0xc420070180, 0xc4200543c0, 0x9)
	/tmp/d20161125-30451-oogwf1/solution_test.go:71 +0x132
created by _/tmp/d20161125-30451-oogwf1.TestWithConccurentSubscribers
	/tmp/d20161125-30451-oogwf1/solution_test.go:76 +0x1c8

goroutine 17 [chan receive]:
_/tmp/d20161125-30451-oogwf1.TestWithConccurentSubscribers.func1(0xc42000a480, 0xc420054420, 0xc420070180, 0xc4200543c0, 0xa)
	/tmp/d20161125-30451-oogwf1/solution_test.go:71 +0x132
created by _/tmp/d20161125-30451-oogwf1.TestWithConccurentSubscribers
	/tmp/d20161125-30451-oogwf1/solution_test.go:76 +0x1c8

goroutine 18 [chan receive]:
_/tmp/d20161125-30451-oogwf1.TestWithConccurentSubscribers.func1(0xc42000a480, 0xc420054420, 0xc420070180, 0xc4200543c0, 0xb)
	/tmp/d20161125-30451-oogwf1/solution_test.go:71 +0x132
created by _/tmp/d20161125-30451-oogwf1.TestWithConccurentSubscribers
	/tmp/d20161125-30451-oogwf1/solution_test.go:76 +0x1c8

goroutine 19 [chan receive]:
_/tmp/d20161125-30451-oogwf1.TestWithConccurentSubscribers.func1(0xc42000a480, 0xc420054420, 0xc420070180, 0xc4200543c0, 0xc)
	/tmp/d20161125-30451-oogwf1/solution_test.go:71 +0x132
created by _/tmp/d20161125-30451-oogwf1.TestWithConccurentSubscribers
	/tmp/d20161125-30451-oogwf1/solution_test.go:76 +0x1c8

goroutine 20 [chan receive]:
_/tmp/d20161125-30451-oogwf1.TestWithConccurentSubscribers.func1(0xc42000a480, 0xc420054420, 0xc420070180, 0xc4200543c0, 0xd)
	/tmp/d20161125-30451-oogwf1/solution_test.go:71 +0x132
created by _/tmp/d20161125-30451-oogwf1.TestWithConccurentSubscribers
	/tmp/d20161125-30451-oogwf1/solution_test.go:76 +0x1c8

goroutine 21 [chan receive]:
_/tmp/d20161125-30451-oogwf1.TestWithConccurentSubscribers.func1(0xc42000a480, 0xc420054420, 0xc420070180, 0xc4200543c0, 0xe)
	/tmp/d20161125-30451-oogwf1/solution_test.go:71 +0x132
created by _/tmp/d20161125-30451-oogwf1.TestWithConccurentSubscribers
	/tmp/d20161125-30451-oogwf1/solution_test.go:76 +0x1c8

goroutine 22 [chan receive]:
_/tmp/d20161125-30451-oogwf1.TestWithConccurentSubscribers.func1(0xc42000a480, 0xc420054420, 0xc420070180, 0xc4200543c0, 0xf)
	/tmp/d20161125-30451-oogwf1/solution_test.go:71 +0x132
created by _/tmp/d20161125-30451-oogwf1.TestWithConccurentSubscribers
	/tmp/d20161125-30451-oogwf1/solution_test.go:76 +0x1c8

goroutine 23 [chan receive]:
_/tmp/d20161125-30451-oogwf1.TestWithConccurentSubscribers.func1(0xc42000a480, 0xc420054420, 0xc420070180, 0xc4200543c0, 0x10)
	/tmp/d20161125-30451-oogwf1/solution_test.go:71 +0x132
created by _/tmp/d20161125-30451-oogwf1.TestWithConccurentSubscribers
	/tmp/d20161125-30451-oogwf1/solution_test.go:76 +0x1c8

goroutine 24 [chan receive]:
_/tmp/d20161125-30451-oogwf1.TestWithConccurentSubscribers.func1(0xc42000a480, 0xc420054420, 0xc420070180, 0xc4200543c0, 0x11)
	/tmp/d20161125-30451-oogwf1/solution_test.go:71 +0x132
created by _/tmp/d20161125-30451-oogwf1.TestWithConccurentSubscribers
	/tmp/d20161125-30451-oogwf1/solution_test.go:76 +0x1c8

goroutine 25 [chan receive]:
_/tmp/d20161125-30451-oogwf1.TestWithConccurentSubscribers.func1(0xc42000a480, 0xc420054420, 0xc420070180, 0xc4200543c0, 0x12)
	/tmp/d20161125-30451-oogwf1/solution_test.go:71 +0x132
created by _/tmp/d20161125-30451-oogwf1.TestWithConccurentSubscribers
	/tmp/d20161125-30451-oogwf1/solution_test.go:76 +0x1c8

goroutine 26 [chan receive]:
_/tmp/d20161125-30451-oogwf1.TestWithConccurentSubscribers.func1(0xc42000a480, 0xc420054420, 0xc420070180, 0xc4200543c0, 0x13)
	/tmp/d20161125-30451-oogwf1/solution_test.go:71 +0x132
created by _/tmp/d20161125-30451-oogwf1.TestWithConccurentSubscribers
	/tmp/d20161125-30451-oogwf1/solution_test.go:76 +0x1c8
exit status 2
FAIL	_/tmp/d20161125-30451-oogwf1	1.006s
PASS
ok  	_/tmp/d20161125-30451-oogwf1	0.003s
panic: test timed out after 1s

goroutine 9 [running]:
panic(0x4ebe40, 0xc4200106c0)
	/usr/local/go/src/runtime/panic.go:500 +0x1a1
testing.startAlarm.func1()
	/usr/local/go/src/testing/testing.go:918 +0x10b
created by time.goFunc
	/usr/local/go/src/time/sleep.go:154 +0x44

goroutine 1 [chan receive]:
testing.(*T).Run(0xc4200700c0, 0x5173f8, 0x16, 0x523850, 0xc42003bd01)
	/usr/local/go/src/testing/testing.go:647 +0x316
testing.RunTests.func1(0xc4200700c0)
	/usr/local/go/src/testing/testing.go:793 +0x6d
testing.tRunner(0xc4200700c0, 0xc42003be20)
	/usr/local/go/src/testing/testing.go:610 +0x81
testing.RunTests(0x5238b0, 0x59e100, 0x6, 0x6, 0x5158e0)
	/usr/local/go/src/testing/testing.go:799 +0x2f5
testing.(*M).Run(0xc42003bee8, 0xc420010510)
	/usr/local/go/src/testing/testing.go:743 +0x85
main.main()
	_/tmp/d20161125-30451-oogwf1/_test/_testmain.go:66 +0xc6

goroutine 6 [chan receive]:
testing.tRunner.func1(0xc420070180)
	/usr/local/go/src/testing/testing.go:590 +0x164
testing.tRunner(0xc420070180, 0x523850)
	/usr/local/go/src/testing/testing.go:612 +0x8b
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:646 +0x2ec

goroutine 7 [chan send]:
_/tmp/d20161125-30451-oogwf1.TestCorrectConcurrency.func1(0xc420070240)
	/tmp/d20161125-30451-oogwf1/solution_test.go:118 +0x233
testing.tRunner(0xc420070240, 0x523848)
	/usr/local/go/src/testing/testing.go:610 +0x81
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:646 +0x2ec

goroutine 8 [chan receive]:
testing.(*testContext).waitParallel(0xc42000a450)
	/usr/local/go/src/testing/testing.go:690 +0xab
testing.(*T).Parallel(0xc420070300)
	/usr/local/go/src/testing/testing.go:553 +0x167
_/tmp/d20161125-30451-oogwf1.TestCorrectConcurrency.func1(0xc420070300)
	/tmp/d20161125-30451-oogwf1/solution_test.go:115 +0x43
testing.tRunner(0xc420070300, 0x523848)
	/usr/local/go/src/testing/testing.go:610 +0x81
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:646 +0x2ec

goroutine 17 [chan receive]:
testing.(*testContext).waitParallel(0xc42000a450)
	/usr/local/go/src/testing/testing.go:690 +0xab
testing.(*T).Parallel(0xc4200900c0)
	/usr/local/go/src/testing/testing.go:553 +0x167
_/tmp/d20161125-30451-oogwf1.TestCorrectConcurrency.func1(0xc4200900c0)
	/tmp/d20161125-30451-oogwf1/solution_test.go:115 +0x43
testing.tRunner(0xc4200900c0, 0x523848)
	/usr/local/go/src/testing/testing.go:610 +0x81
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:646 +0x2ec

goroutine 18 [chan receive]:
testing.(*testContext).waitParallel(0xc42000a450)
	/usr/local/go/src/testing/testing.go:690 +0xab
testing.(*T).Parallel(0xc420090180)
	/usr/local/go/src/testing/testing.go:553 +0x167
_/tmp/d20161125-30451-oogwf1.TestCorrectConcurrency.func1(0xc420090180)
	/tmp/d20161125-30451-oogwf1/solution_test.go:115 +0x43
testing.tRunner(0xc420090180, 0x523848)
	/usr/local/go/src/testing/testing.go:610 +0x81
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:646 +0x2ec

goroutine 19 [chan receive]:
testing.(*testContext).waitParallel(0xc42000a450)
	/usr/local/go/src/testing/testing.go:690 +0xab
testing.(*T).Parallel(0xc420090240)
	/usr/local/go/src/testing/testing.go:553 +0x167
_/tmp/d20161125-30451-oogwf1.TestCorrectConcurrency.func1(0xc420090240)
	/tmp/d20161125-30451-oogwf1/solution_test.go:115 +0x43
testing.tRunner(0xc420090240, 0x523848)
	/usr/local/go/src/testing/testing.go:610 +0x81
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:646 +0x2ec

goroutine 20 [chan receive]:
testing.(*testContext).waitParallel(0xc42000a450)
	/usr/local/go/src/testing/testing.go:690 +0xab
testing.(*T).Parallel(0xc420090300)
	/usr/local/go/src/testing/testing.go:553 +0x167
_/tmp/d20161125-30451-oogwf1.TestCorrectConcurrency.func1(0xc420090300)
	/tmp/d20161125-30451-oogwf1/solution_test.go:115 +0x43
testing.tRunner(0xc420090300, 0x523848)
	/usr/local/go/src/testing/testing.go:610 +0x81
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:646 +0x2ec

goroutine 21 [chan receive]:
testing.(*testContext).waitParallel(0xc42000a450)
	/usr/local/go/src/testing/testing.go:690 +0xab
testing.(*T).Parallel(0xc4200903c0)
	/usr/local/go/src/testing/testing.go:553 +0x167
_/tmp/d20161125-30451-oogwf1.TestCorrectConcurrency.func1(0xc4200903c0)
	/tmp/d20161125-30451-oogwf1/solution_test.go:115 +0x43
testing.tRunner(0xc4200903c0, 0x523848)
	/usr/local/go/src/testing/testing.go:610 +0x81
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:646 +0x2ec

goroutine 22 [chan receive]:
testing.(*testContext).waitParallel(0xc42000a450)
	/usr/local/go/src/testing/testing.go:690 +0xab
testing.(*T).Parallel(0xc420090480)
	/usr/local/go/src/testing/testing.go:553 +0x167
_/tmp/d20161125-30451-oogwf1.TestCorrectConcurrency.func1(0xc420090480)
	/tmp/d20161125-30451-oogwf1/solution_test.go:115 +0x43
testing.tRunner(0xc420090480, 0x523848)
	/usr/local/go/src/testing/testing.go:610 +0x81
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:646 +0x2ec

goroutine 23 [chan receive]:
testing.(*testContext).waitParallel(0xc42000a450)
	/usr/local/go/src/testing/testing.go:690 +0xab
testing.(*T).Parallel(0xc420090540)
	/usr/local/go/src/testing/testing.go:553 +0x167
_/tmp/d20161125-30451-oogwf1.TestCorrectConcurrency.func1(0xc420090540)
	/tmp/d20161125-30451-oogwf1/solution_test.go:115 +0x43
testing.tRunner(0xc420090540, 0x523848)
	/usr/local/go/src/testing/testing.go:610 +0x81
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:646 +0x2ec

goroutine 24 [chan send]:
_/tmp/d20161125-30451-oogwf1.TestCorrectConcurrency.func1(0xc420090600)
	/tmp/d20161125-30451-oogwf1/solution_test.go:118 +0x233
testing.tRunner(0xc420090600, 0x523848)
	/usr/local/go/src/testing/testing.go:610 +0x81
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:646 +0x2ec
exit status 2
FAIL	_/tmp/d20161125-30451-oogwf1	1.006s
Георги Серев
  • Некоректно
  • 5 успешни тест(а)
  • 1 неуспешни тест(а)
Георги Серев
package main
import "fmt"
// PubSub ...
type PubSub struct {
listeners []chan string
channel chan string
}
// Subscribe ...
func (p *PubSub) Subscribe() <-chan string {
ch := make(chan string)
p.listeners = append(p.listeners, ch)
return ch
}
// Publish ...
func (p *PubSub) Publish() chan<- string {
go func() {
val := <-p.channel
for _, ch := range p.listeners {
ch <- val
}
}()
return p.channel
}
// NewPubSub ...
func NewPubSub() *PubSub {
ps := PubSub{[]chan string{}, make(chan string)}
return &ps
}
func main() {
ps := NewPubSub()
a := ps.Subscribe()
b := ps.Subscribe()
c := ps.Subscribe()
go func() {
ps.Publish() <- "wat"
ps.Publish() <- ("wat" + <-c)
}()
fmt.Printf("A recieved %s, B recieved %s and we ignore C!\n", <-a, <-b)
fmt.Printf("A recieved %s, B recieved %s and C received %s\n", <-a, <-b, <-c)
}
PASS
ok  	_/tmp/d20161125-30451-103wrqz	0.003s
PASS
ok  	_/tmp/d20161125-30451-103wrqz	0.003s
PASS
ok  	_/tmp/d20161125-30451-103wrqz	0.103s
panic: test timed out after 1s

goroutine 42 [running]:
panic(0x4eae60, 0xc42005e4e0)
	/usr/local/go/src/runtime/panic.go:500 +0x1a1
testing.startAlarm.func1()
	/usr/local/go/src/testing/testing.go:918 +0x10b
created by time.goFunc
	/usr/local/go/src/time/sleep.go:154 +0x44

goroutine 1 [chan receive]:
testing.(*T).Run(0xc4200820c0, 0x517b56, 0x1d, 0x522888, 0xc42003bd01)
	/usr/local/go/src/testing/testing.go:647 +0x316
testing.RunTests.func1(0xc4200820c0)
	/usr/local/go/src/testing/testing.go:793 +0x6d
testing.tRunner(0xc4200820c0, 0xc42003be20)
	/usr/local/go/src/testing/testing.go:610 +0x81
testing.RunTests(0x5228b8, 0x59d100, 0x6, 0x6, 0x514940)
	/usr/local/go/src/testing/testing.go:799 +0x2f5
testing.(*M).Run(0xc42003bee8, 0xc42005e3e0)
	/usr/local/go/src/testing/testing.go:743 +0x85
main.main()
	_/tmp/d20161125-30451-103wrqz/_test/_testmain.go:66 +0xc6

goroutine 20 [chan receive]:
_/tmp/d20161125-30451-103wrqz.TestWithConccurentSubscribers(0xc420082180)
	/tmp/d20161125-30451-103wrqz/solution_test.go:86 +0x232
testing.tRunner(0xc420082180, 0x522888)
	/usr/local/go/src/testing/testing.go:610 +0x81
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:646 +0x2ec

goroutine 16 [chan receive]:
_/tmp/d20161125-30451-103wrqz.TestWithConccurentSubscribers.func1(0xc42000e300, 0xc4200a81e0, 0xc420082180, 0xc4200a8180, 0xd)
	/tmp/d20161125-30451-103wrqz/solution_test.go:71 +0x104
created by _/tmp/d20161125-30451-103wrqz.TestWithConccurentSubscribers
	/tmp/d20161125-30451-103wrqz/solution_test.go:76 +0x15b

goroutine 49 [chan receive]:
_/tmp/d20161125-30451-103wrqz.TestWithConccurentSubscribers.func1(0xc42000e300, 0xc4200a81e0, 0xc420082180, 0xc4200a8180, 0xe)
	/tmp/d20161125-30451-103wrqz/solution_test.go:71 +0x104
created by _/tmp/d20161125-30451-103wrqz.TestWithConccurentSubscribers
	/tmp/d20161125-30451-103wrqz/solution_test.go:76 +0x15b
exit status 2
FAIL	_/tmp/d20161125-30451-103wrqz	1.005s
PASS
ok  	_/tmp/d20161125-30451-103wrqz	0.003s
PASS
ok  	_/tmp/d20161125-30451-103wrqz	0.054s
Николай Бабулков
  • Некоректно
  • 4 успешни тест(а)
  • 2 неуспешни тест(а)
Николай Бабулков
package main
type PubSub struct {
mesgChan chan string
subscriberChans []chan string
}
func (p *PubSub) Subscribe() <-chan string {
newRecieveChan := make(chan string)
p.subscriberChans = append(p.subscriberChans, newRecieveChan)
go func() {
for {
str := <-p.mesgChan
for _, subChan := range p.subscriberChans {
subChan <- str
}
}
}()
return newRecieveChan
}
func (p *PubSub) Publish() chan<- string {
newSendChan := make(chan string)
go func() {
for {
p.mesgChan <- <-newSendChan
}
}()
return newSendChan
}
func NewPubSub() *PubSub {
mChan := make(chan string)
return &PubSub{mesgChan: mChan}
}
PASS
ok  	_/tmp/d20161125-30451-1kzdu4t	0.003s
PASS
ok  	_/tmp/d20161125-30451-1kzdu4t	0.003s
--- FAIL: TestLateSubscriber (0.05s)
	solution_test.go:55: Expected later subscribers not to receive missed messages but recieved test
FAIL
exit status 1
FAIL	_/tmp/d20161125-30451-1kzdu4t	0.053s
panic: test timed out after 1s

goroutine 97 [running]:
panic(0x4eae80, 0xc42005e4e0)
	/usr/local/go/src/runtime/panic.go:500 +0x1a1
testing.startAlarm.func1()
	/usr/local/go/src/testing/testing.go:918 +0x10b
created by time.goFunc
	/usr/local/go/src/time/sleep.go:154 +0x44

goroutine 1 [chan receive]:
testing.(*T).Run(0xc4200820c0, 0x517b16, 0x1d, 0x5227b0, 0xc42003bd01)
	/usr/local/go/src/testing/testing.go:647 +0x316
testing.RunTests.func1(0xc4200820c0)
	/usr/local/go/src/testing/testing.go:793 +0x6d
testing.tRunner(0xc4200820c0, 0xc42003be20)
	/usr/local/go/src/testing/testing.go:610 +0x81
testing.RunTests(0x5227e0, 0x59d100, 0x6, 0x6, 0x514900)
	/usr/local/go/src/testing/testing.go:799 +0x2f5
testing.(*M).Run(0xc42003bee8, 0xc42005e3e0)
	/usr/local/go/src/testing/testing.go:743 +0x85
main.main()
	_/tmp/d20161125-30451-1kzdu4t/_test/_testmain.go:66 +0xc6

goroutine 20 [chan receive]:
_/tmp/d20161125-30451-1kzdu4t.TestWithConccurentSubscribers(0xc420082180)
	/tmp/d20161125-30451-1kzdu4t/solution_test.go:86 +0x221
testing.tRunner(0xc420082180, 0x5227b0)
	/usr/local/go/src/testing/testing.go:610 +0x81
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:646 +0x2ec

goroutine 3 [chan receive]:
_/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe.func1(0xc420058140)
	/tmp/d20161125-30451-1kzdu4t/solution.go:13 +0x5a
created by _/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe
	/tmp/d20161125-30451-1kzdu4t/solution.go:18 +0x9f

goroutine 4 [chan receive]:
_/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe.func1(0xc420058140)
	/tmp/d20161125-30451-1kzdu4t/solution.go:13 +0x5a
created by _/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe
	/tmp/d20161125-30451-1kzdu4t/solution.go:18 +0x9f

goroutine 56 [chan receive]:
_/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe.func1(0xc42000e300)
	/tmp/d20161125-30451-1kzdu4t/solution.go:13 +0x5a
created by _/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe
	/tmp/d20161125-30451-1kzdu4t/solution.go:18 +0x9f

goroutine 5 [chan receive]:
_/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe.func1(0xc420058140)
	/tmp/d20161125-30451-1kzdu4t/solution.go:13 +0x5a
created by _/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe
	/tmp/d20161125-30451-1kzdu4t/solution.go:18 +0x9f

goroutine 53 [chan receive]:
_/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe.func1(0xc42000e300)
	/tmp/d20161125-30451-1kzdu4t/solution.go:13 +0x5a
created by _/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe
	/tmp/d20161125-30451-1kzdu4t/solution.go:18 +0x9f

goroutine 51 [chan receive]:
_/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe.func1(0xc42000e300)
	/tmp/d20161125-30451-1kzdu4t/solution.go:13 +0x5a
created by _/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe
	/tmp/d20161125-30451-1kzdu4t/solution.go:18 +0x9f

goroutine 55 [chan receive]:
_/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe.func1(0xc42000e300)
	/tmp/d20161125-30451-1kzdu4t/solution.go:13 +0x5a
created by _/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe
	/tmp/d20161125-30451-1kzdu4t/solution.go:18 +0x9f

goroutine 54 [chan receive]:
_/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe.func1(0xc42000e300)
	/tmp/d20161125-30451-1kzdu4t/solution.go:13 +0x5a
created by _/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe
	/tmp/d20161125-30451-1kzdu4t/solution.go:18 +0x9f

goroutine 52 [chan receive]:
_/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe.func1(0xc42000e300)
	/tmp/d20161125-30451-1kzdu4t/solution.go:13 +0x5a
created by _/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe
	/tmp/d20161125-30451-1kzdu4t/solution.go:18 +0x9f

goroutine 50 [chan receive]:
_/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe.func1(0xc42000e300)
	/tmp/d20161125-30451-1kzdu4t/solution.go:13 +0x5a
created by _/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe
	/tmp/d20161125-30451-1kzdu4t/solution.go:18 +0x9f

goroutine 57 [chan receive]:
_/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe.func1(0xc42000e300)
	/tmp/d20161125-30451-1kzdu4t/solution.go:13 +0x5a
created by _/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe
	/tmp/d20161125-30451-1kzdu4t/solution.go:18 +0x9f

goroutine 6 [chan receive]:
_/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe.func1(0xc420058140)
	/tmp/d20161125-30451-1kzdu4t/solution.go:13 +0x5a
created by _/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe
	/tmp/d20161125-30451-1kzdu4t/solution.go:18 +0x9f

goroutine 7 [chan receive]:
_/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe.func1(0xc420058140)
	/tmp/d20161125-30451-1kzdu4t/solution.go:13 +0x5a
created by _/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe
	/tmp/d20161125-30451-1kzdu4t/solution.go:18 +0x9f

goroutine 8 [chan receive]:
_/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe.func1(0xc420058140)
	/tmp/d20161125-30451-1kzdu4t/solution.go:13 +0x5a
created by _/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe
	/tmp/d20161125-30451-1kzdu4t/solution.go:18 +0x9f

goroutine 9 [chan receive]:
_/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe.func1(0xc420058140)
	/tmp/d20161125-30451-1kzdu4t/solution.go:13 +0x5a
created by _/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe
	/tmp/d20161125-30451-1kzdu4t/solution.go:18 +0x9f

goroutine 41 [chan receive]:
_/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe.func1(0xc420058140)
	/tmp/d20161125-30451-1kzdu4t/solution.go:13 +0x5a
created by _/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe
	/tmp/d20161125-30451-1kzdu4t/solution.go:18 +0x9f

goroutine 10 [chan receive]:
_/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe.func1(0xc420058140)
	/tmp/d20161125-30451-1kzdu4t/solution.go:13 +0x5a
created by _/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe
	/tmp/d20161125-30451-1kzdu4t/solution.go:18 +0x9f

goroutine 42 [chan receive]:
_/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe.func1(0xc420058140)
	/tmp/d20161125-30451-1kzdu4t/solution.go:13 +0x5a
created by _/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe
	/tmp/d20161125-30451-1kzdu4t/solution.go:18 +0x9f

goroutine 43 [chan receive]:
_/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe.func1(0xc420058140)
	/tmp/d20161125-30451-1kzdu4t/solution.go:13 +0x5a
created by _/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe
	/tmp/d20161125-30451-1kzdu4t/solution.go:18 +0x9f

goroutine 11 [chan receive]:
_/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe.func1(0xc420058140)
	/tmp/d20161125-30451-1kzdu4t/solution.go:13 +0x5a
created by _/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe
	/tmp/d20161125-30451-1kzdu4t/solution.go:18 +0x9f

goroutine 44 [chan receive]:
_/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe.func1(0xc420058140)
	/tmp/d20161125-30451-1kzdu4t/solution.go:13 +0x5a
created by _/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe
	/tmp/d20161125-30451-1kzdu4t/solution.go:18 +0x9f

goroutine 12 [chan receive]:
_/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe.func1(0xc420058140)
	/tmp/d20161125-30451-1kzdu4t/solution.go:13 +0x5a
created by _/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe
	/tmp/d20161125-30451-1kzdu4t/solution.go:18 +0x9f

goroutine 45 [chan receive]:
_/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe.func1(0xc420058140)
	/tmp/d20161125-30451-1kzdu4t/solution.go:13 +0x5a
created by _/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe
	/tmp/d20161125-30451-1kzdu4t/solution.go:18 +0x9f

goroutine 13 [chan receive]:
_/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe.func1(0xc420058140)
	/tmp/d20161125-30451-1kzdu4t/solution.go:13 +0x5a
created by _/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe
	/tmp/d20161125-30451-1kzdu4t/solution.go:18 +0x9f

goroutine 46 [chan receive]:
_/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe.func1(0xc420058140)
	/tmp/d20161125-30451-1kzdu4t/solution.go:13 +0x5a
created by _/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe
	/tmp/d20161125-30451-1kzdu4t/solution.go:18 +0x9f

goroutine 14 [chan receive]:
_/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe.func1(0xc420058140)
	/tmp/d20161125-30451-1kzdu4t/solution.go:13 +0x5a
created by _/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe
	/tmp/d20161125-30451-1kzdu4t/solution.go:18 +0x9f

goroutine 47 [chan receive]:
_/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe.func1(0xc420058140)
	/tmp/d20161125-30451-1kzdu4t/solution.go:13 +0x5a
created by _/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe
	/tmp/d20161125-30451-1kzdu4t/solution.go:18 +0x9f

goroutine 48 [chan receive]:
_/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe.func1(0xc420058140)
	/tmp/d20161125-30451-1kzdu4t/solution.go:13 +0x5a
created by _/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe
	/tmp/d20161125-30451-1kzdu4t/solution.go:18 +0x9f

goroutine 49 [chan receive]:
_/tmp/d20161125-30451-1kzdu4t.(*PubSub).Publish.func1(0xc420058140, 0xc42005c780)
	/tmp/d20161125-30451-1kzdu4t/solution.go:26 +0x53
created by _/tmp/d20161125-30451-1kzdu4t.(*PubSub).Publish
	/tmp/d20161125-30451-1kzdu4t/solution.go:28 +0x67

goroutine 76 [chan receive]:
_/tmp/d20161125-30451-1kzdu4t.TestWithConccurentSubscribers.func1(0xc42000e300, 0xc4200a8540, 0xc420082180, 0xc4200a84e0, 0xd)
	/tmp/d20161125-30451-1kzdu4t/solution_test.go:71 +0xb7
created by _/tmp/d20161125-30451-1kzdu4t.TestWithConccurentSubscribers
	/tmp/d20161125-30451-1kzdu4t/solution_test.go:76 +0x14a

goroutine 83 [chan receive]:
_/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe.func1(0xc42000e300)
	/tmp/d20161125-30451-1kzdu4t/solution.go:13 +0x5a
created by _/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe
	/tmp/d20161125-30451-1kzdu4t/solution.go:18 +0x9f

goroutine 84 [chan receive]:
_/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe.func1(0xc42000e300)
	/tmp/d20161125-30451-1kzdu4t/solution.go:13 +0x5a
created by _/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe
	/tmp/d20161125-30451-1kzdu4t/solution.go:18 +0x9f

goroutine 85 [chan receive]:
_/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe.func1(0xc42000e300)
	/tmp/d20161125-30451-1kzdu4t/solution.go:13 +0x5a
created by _/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe
	/tmp/d20161125-30451-1kzdu4t/solution.go:18 +0x9f

goroutine 58 [chan receive]:
_/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe.func1(0xc42000e300)
	/tmp/d20161125-30451-1kzdu4t/solution.go:13 +0x5a
created by _/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe
	/tmp/d20161125-30451-1kzdu4t/solution.go:18 +0x9f

goroutine 59 [chan receive]:
_/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe.func1(0xc42000e300)
	/tmp/d20161125-30451-1kzdu4t/solution.go:13 +0x5a
created by _/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe
	/tmp/d20161125-30451-1kzdu4t/solution.go:18 +0x9f

goroutine 60 [chan receive]:
_/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe.func1(0xc42000e300)
	/tmp/d20161125-30451-1kzdu4t/solution.go:13 +0x5a
created by _/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe
	/tmp/d20161125-30451-1kzdu4t/solution.go:18 +0x9f

goroutine 61 [chan receive]:
_/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe.func1(0xc42000e300)
	/tmp/d20161125-30451-1kzdu4t/solution.go:13 +0x5a
created by _/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe
	/tmp/d20161125-30451-1kzdu4t/solution.go:18 +0x9f

goroutine 62 [chan receive]:
_/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe.func1(0xc42000e300)
	/tmp/d20161125-30451-1kzdu4t/solution.go:13 +0x5a
created by _/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe
	/tmp/d20161125-30451-1kzdu4t/solution.go:18 +0x9f

goroutine 86 [chan receive]:
_/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe.func1(0xc42000e300)
	/tmp/d20161125-30451-1kzdu4t/solution.go:13 +0x5a
created by _/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe
	/tmp/d20161125-30451-1kzdu4t/solution.go:18 +0x9f

goroutine 63 [chan receive]:
_/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe.func1(0xc42000e300)
	/tmp/d20161125-30451-1kzdu4t/solution.go:13 +0x5a
created by _/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe
	/tmp/d20161125-30451-1kzdu4t/solution.go:18 +0x9f

goroutine 87 [chan receive]:
_/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe.func1(0xc42000e300)
	/tmp/d20161125-30451-1kzdu4t/solution.go:13 +0x5a
created by _/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe
	/tmp/d20161125-30451-1kzdu4t/solution.go:18 +0x9f

goroutine 64 [chan receive]:
_/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe.func1(0xc42000e300)
	/tmp/d20161125-30451-1kzdu4t/solution.go:13 +0x5a
created by _/tmp/d20161125-30451-1kzdu4t.(*PubSub).Subscribe
	/tmp/d20161125-30451-1kzdu4t/solution.go:18 +0x9f

goroutine 88 [chan receive]:
_/tmp/d20161125-30451-1kzdu4t.(*PubSub).Publish.func1(0xc42000e300, 0xc4200a8780)
	/tmp/d20161125-30451-1kzdu4t/solution.go:26 +0x53
created by _/tmp/d20161125-30451-1kzdu4t.(*PubSub).Publish
	/tmp/d20161125-30451-1kzdu4t/solution.go:28 +0x67
exit status 2
FAIL	_/tmp/d20161125-30451-1kzdu4t	1.014s
PASS
ok  	_/tmp/d20161125-30451-1kzdu4t	0.003s
PASS
ok  	_/tmp/d20161125-30451-1kzdu4t	0.053s
Кирил Костов
  • Некоректно
  • 5 успешни тест(а)
  • 1 неуспешни тест(а)
Кирил Костов
package main
type PubSub struct {
channels []chan string
}
func (pubSub *PubSub) Subscribe() <-chan string {
pubSub.channels = append(pubSub.channels, make(chan string))
return pubSub.channels[len(pubSub.channels)-1]
}
func (pubSub *PubSub) Publish() chan<- string {
recieve := make(chan string)
go func() {
str := <-recieve
go func() {
for _, channel := range pubSub.channels {
channel <- str
}
}()
}()
return recieve
}
func NewPubSub() *PubSub {
pubSub := &PubSub{channels: make([]chan string, 0)}
return pubSub
}
PASS
ok  	_/tmp/d20161125-30451-vozovh	0.002s
PASS
ok  	_/tmp/d20161125-30451-vozovh	0.003s
PASS
ok  	_/tmp/d20161125-30451-vozovh	0.103s
panic: test timed out after 1s

goroutine 29 [running]:
panic(0x4eae40, 0xc420010600)
	/usr/local/go/src/runtime/panic.go:500 +0x1a1
testing.startAlarm.func1()
	/usr/local/go/src/testing/testing.go:918 +0x10b
created by time.goFunc
	/usr/local/go/src/time/sleep.go:154 +0x44

goroutine 1 [chan receive]:
testing.(*T).Run(0xc4200720c0, 0x517ab6, 0x1d, 0x522790, 0xc42003bd01)
	/usr/local/go/src/testing/testing.go:647 +0x316
testing.RunTests.func1(0xc4200720c0)
	/usr/local/go/src/testing/testing.go:793 +0x6d
testing.tRunner(0xc4200720c0, 0xc42003be20)
	/usr/local/go/src/testing/testing.go:610 +0x81
testing.RunTests(0x5227c0, 0x59d100, 0x6, 0x6, 0x5148a0)
	/usr/local/go/src/testing/testing.go:799 +0x2f5
testing.(*M).Run(0xc42003bee8, 0xc420010510)
	/usr/local/go/src/testing/testing.go:743 +0x85
main.main()
	_/tmp/d20161125-30451-vozovh/_test/_testmain.go:66 +0xc6

goroutine 6 [chan receive]:
_/tmp/d20161125-30451-vozovh.TestWithConccurentSubscribers(0xc420072180)
	/tmp/d20161125-30451-vozovh/solution_test.go:86 +0x23d
testing.tRunner(0xc420072180, 0x522790)
	/usr/local/go/src/testing/testing.go:610 +0x81
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:646 +0x2ec

goroutine 13 [chan receive]:
_/tmp/d20161125-30451-vozovh.TestWithConccurentSubscribers.func1(0xc42000e420, 0xc4200563c0, 0xc420072180, 0xc420056360, 0x6)
	/tmp/d20161125-30451-vozovh/solution_test.go:71 +0x128
created by _/tmp/d20161125-30451-vozovh.TestWithConccurentSubscribers
	/tmp/d20161125-30451-vozovh/solution_test.go:76 +0x160

goroutine 14 [chan receive]:
_/tmp/d20161125-30451-vozovh.TestWithConccurentSubscribers.func1(0xc42000e420, 0xc4200563c0, 0xc420072180, 0xc420056360, 0x7)
	/tmp/d20161125-30451-vozovh/solution_test.go:71 +0x128
created by _/tmp/d20161125-30451-vozovh.TestWithConccurentSubscribers
	/tmp/d20161125-30451-vozovh/solution_test.go:76 +0x160

goroutine 15 [chan receive]:
_/tmp/d20161125-30451-vozovh.TestWithConccurentSubscribers.func1(0xc42000e420, 0xc4200563c0, 0xc420072180, 0xc420056360, 0x8)
	/tmp/d20161125-30451-vozovh/solution_test.go:71 +0x128
created by _/tmp/d20161125-30451-vozovh.TestWithConccurentSubscribers
	/tmp/d20161125-30451-vozovh/solution_test.go:76 +0x160

goroutine 16 [chan receive]:
_/tmp/d20161125-30451-vozovh.TestWithConccurentSubscribers.func1(0xc42000e420, 0xc4200563c0, 0xc420072180, 0xc420056360, 0x9)
	/tmp/d20161125-30451-vozovh/solution_test.go:71 +0x128
created by _/tmp/d20161125-30451-vozovh.TestWithConccurentSubscribers
	/tmp/d20161125-30451-vozovh/solution_test.go:76 +0x160
exit status 2
FAIL	_/tmp/d20161125-30451-vozovh	1.005s
PASS
ok  	_/tmp/d20161125-30451-vozovh	0.003s
PASS
ok  	_/tmp/d20161125-30451-vozovh	0.053s
Никола Юруков
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Никола Юруков
package main
// PubSub is a simple publish-subscribe system.
type PubSub struct {
main chan string
recipients []chan string
}
// Subscribe creates a channel to receive published messages.
func (ps *PubSub) Subscribe() <-chan string {
newChannel := make(chan string)
ps.recipients = append(ps.recipients, newChannel)
return newChannel
}
// Publish gives access to the broadcast channel for publishing messages.
func (ps *PubSub) Publish() chan<- string {
return ps.main
}
// NewPubSub initialises and returns a new PubSub object.
func NewPubSub() *PubSub {
ps := new(PubSub)
ps.main = make(chan string)
ps.recipients = make([]chan string, 0, 100)
go readAndDistribute(ps)
return ps
}
// readAndDistribute reads from the input channel and writes copies of the value to the receiving channels
func readAndDistribute(ps *PubSub) {
for broadcastVal := range ps.main {
syncChan := make(chan struct{})
for _, c := range ps.recipients {
// Creates "new" copies, so that they don't get modified inside
// the closure
broadcastVal, c := broadcastVal, c
go func() {
c <- broadcastVal
syncChan <- struct{}{}
}()
}
for range ps.recipients {
<-syncChan
}
}
}
PASS
ok  	_/tmp/d20161125-30451-nhmev6	0.003s
PASS
ok  	_/tmp/d20161125-30451-nhmev6	0.003s
PASS
ok  	_/tmp/d20161125-30451-nhmev6	0.103s
PASS
ok  	_/tmp/d20161125-30451-nhmev6	0.025s
PASS
ok  	_/tmp/d20161125-30451-nhmev6	0.003s
PASS
ok  	_/tmp/d20161125-30451-nhmev6	0.054s
Слави Боянов
  • Коректно
  • 6 успешни тест(а)
  • 0 неуспешни тест(а)
Слави Боянов
package main
type PubSub struct {
subscribers []chan string
sync chan struct{}
}
func NewPubSub() PubSub {
return PubSub{make([]chan string, 0), make(chan struct{}, 1)}
}
func (ps *PubSub) lock() {
ps.sync <- struct{}{}
}
func (ps *PubSub) unlock() {
<-ps.sync
}
func (ps *PubSub) Subscribe() <-chan string {
ps.lock()
defer ps.unlock()
ps.subscribers = append(ps.subscribers, make(chan string))
return ps.subscribers[len(ps.subscribers)-1]
}
func (ps *PubSub) Publish() chan<- string {
publisher := make(chan string)
go func() {
for message := range publisher {
subscribers := ps.subscribers
ps.lock()
for _, subscriber := range subscribers {
subscriber <- message
}
ps.unlock()
}
}()
return publisher
}
PASS
ok  	_/tmp/d20161125-30451-pdej90	0.003s
PASS
ok  	_/tmp/d20161125-30451-pdej90	0.003s
PASS
ok  	_/tmp/d20161125-30451-pdej90	0.102s
PASS
ok  	_/tmp/d20161125-30451-pdej90	0.022s
PASS
ok  	_/tmp/d20161125-30451-pdej90	0.005s
PASS
ok  	_/tmp/d20161125-30451-pdej90	0.054s
Димитър Влаховски
  • Некоректно
  • 5 успешни тест(а)
  • 1 неуспешни тест(а)
Димитър Влаховски
package main
type PubSub struct {
subscribers []chan string
publish chan string
}
func NewPubSub() *PubSub {
ps := new(PubSub)
ps.subscribers = make([]chan string, 0)
ps.publish = make(chan string)
return ps
}
func (p *PubSub) Subscribe() <-chan string {
ch := make(chan string)
p.subscribers = append(p.subscribers, ch)
return ch
}
func (p *PubSub) Publish() chan<- string {
go func() {
value := <-p.publish
for i := range p.subscribers {
p.subscribers[i] <- value
}
}()
return p.publish
}
PASS
ok  	_/tmp/d20161125-30451-xl6wum	0.010s
PASS
ok  	_/tmp/d20161125-30451-xl6wum	0.004s
PASS
ok  	_/tmp/d20161125-30451-xl6wum	0.103s
panic: test timed out after 1s

goroutine 27 [running]:
panic(0x4eae00, 0xc420010600)
	/usr/local/go/src/runtime/panic.go:500 +0x1a1
testing.startAlarm.func1()
	/usr/local/go/src/testing/testing.go:918 +0x10b
created by time.goFunc
	/usr/local/go/src/time/sleep.go:154 +0x44

goroutine 1 [chan receive]:
testing.(*T).Run(0xc4200820c0, 0x517a96, 0x1d, 0x522768, 0xc42003bd01)
	/usr/local/go/src/testing/testing.go:647 +0x316
testing.RunTests.func1(0xc4200820c0)
	/usr/local/go/src/testing/testing.go:793 +0x6d
testing.tRunner(0xc4200820c0, 0xc42003be20)
	/usr/local/go/src/testing/testing.go:610 +0x81
testing.RunTests(0x522798, 0x59d100, 0x6, 0x6, 0x514880)
	/usr/local/go/src/testing/testing.go:799 +0x2f5
testing.(*M).Run(0xc42003bee8, 0xc420010510)
	/usr/local/go/src/testing/testing.go:743 +0x85
main.main()
	_/tmp/d20161125-30451-xl6wum/_test/_testmain.go:66 +0xc6

goroutine 6 [chan receive]:
_/tmp/d20161125-30451-xl6wum.TestWithConccurentSubscribers(0xc420082180)
	/tmp/d20161125-30451-xl6wum/solution_test.go:86 +0x24e
testing.tRunner(0xc420082180, 0x522768)
	/usr/local/go/src/testing/testing.go:610 +0x81
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:646 +0x2ec

goroutine 24 [chan receive]:
_/tmp/d20161125-30451-xl6wum.TestWithConccurentSubscribers.func1(0xc42000e420, 0xc420064420, 0xc420082180, 0xc4200643c0, 0x11)
	/tmp/d20161125-30451-xl6wum/solution_test.go:71 +0x104
created by _/tmp/d20161125-30451-xl6wum.TestWithConccurentSubscribers
	/tmp/d20161125-30451-xl6wum/solution_test.go:76 +0x17a

goroutine 25 [chan receive]:
_/tmp/d20161125-30451-xl6wum.TestWithConccurentSubscribers.func1(0xc42000e420, 0xc420064420, 0xc420082180, 0xc4200643c0, 0x12)
	/tmp/d20161125-30451-xl6wum/solution_test.go:71 +0x104
created by _/tmp/d20161125-30451-xl6wum.TestWithConccurentSubscribers
	/tmp/d20161125-30451-xl6wum/solution_test.go:76 +0x17a
exit status 2
FAIL	_/tmp/d20161125-30451-xl6wum	1.005s
PASS
ok  	_/tmp/d20161125-30451-xl6wum	0.003s
PASS
ok  	_/tmp/d20161125-30451-xl6wum	0.053s
Константин Тодоров
  • Некоректно
  • 4 успешни тест(а)
  • 2 неуспешни тест(а)
Константин Тодоров
package main
type PubSub struct {
listeners []chan string
}
func (p *PubSub) Subscribe() <-chan string {
newChannel := make(chan string)
p.listeners = append(p.listeners, newChannel)
return newChannel
}
func (p *PubSub) Publish() chan<- string {
channelForPublishing := make(chan string)
go func() {
publishedString := <-channelForPublishing
for i := 0; i < len(p.listeners); i++ {
// We have to start new goroutine for every subscriber,
// otherwise subscriber2 won't receive anything until subscriber1 has read the string
go func(s string, c chan string) {
c <- s
}(publishedString, p.listeners[i])
}
}()
return channelForPublishing
}
func NewPubSub() *PubSub {
var newPubSub = PubSub{}
newPubSub.listeners = make([]chan string, 0)
return &newPubSub
}
PASS
ok  	_/tmp/d20161125-30451-710ita	0.003s
PASS
ok  	_/tmp/d20161125-30451-710ita	0.003s
PASS
ok  	_/tmp/d20161125-30451-710ita	0.103s
panic: test timed out after 1s

goroutine 40 [running]:
panic(0x4eae00, 0xc4200564e0)
	/usr/local/go/src/runtime/panic.go:500 +0x1a1
testing.startAlarm.func1()
	/usr/local/go/src/testing/testing.go:918 +0x10b
created by time.goFunc
	/usr/local/go/src/time/sleep.go:154 +0x44

goroutine 1 [chan receive]:
testing.(*T).Run(0xc42007e0c0, 0x517a76, 0x1d, 0x522750, 0xc420035d01)
	/usr/local/go/src/testing/testing.go:647 +0x316
testing.RunTests.func1(0xc42007e0c0)
	/usr/local/go/src/testing/testing.go:793 +0x6d
testing.tRunner(0xc42007e0c0, 0xc420035e20)
	/usr/local/go/src/testing/testing.go:610 +0x81
testing.RunTests(0x522780, 0x59d100, 0x6, 0x6, 0x514860)
	/usr/local/go/src/testing/testing.go:799 +0x2f5
testing.(*M).Run(0xc420035ee8, 0xc4200563e0)
	/usr/local/go/src/testing/testing.go:743 +0x85
main.main()
	_/tmp/d20161125-30451-710ita/_test/_testmain.go:66 +0xc6

goroutine 19 [chan receive]:
_/tmp/d20161125-30451-710ita.TestWithConccurentSubscribers(0xc42007e180)
	/tmp/d20161125-30451-710ita/solution_test.go:86 +0x22c
testing.tRunner(0xc42007e180, 0x522750)
	/usr/local/go/src/testing/testing.go:610 +0x81
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:646 +0x2ec

goroutine 27 [chan receive]:
_/tmp/d20161125-30451-710ita.TestWithConccurentSubscribers.func1(0xc42006a100, 0xc4200543c0, 0xc42007e180, 0xc420054360, 0x7)
	/tmp/d20161125-30451-710ita/solution_test.go:71 +0x104
created by _/tmp/d20161125-30451-710ita.TestWithConccurentSubscribers
	/tmp/d20161125-30451-710ita/solution_test.go:76 +0x158

goroutine 28 [chan receive]:
_/tmp/d20161125-30451-710ita.TestWithConccurentSubscribers.func1(0xc42006a100, 0xc4200543c0, 0xc42007e180, 0xc420054360, 0x8)
	/tmp/d20161125-30451-710ita/solution_test.go:71 +0x104
created by _/tmp/d20161125-30451-710ita.TestWithConccurentSubscribers
	/tmp/d20161125-30451-710ita/solution_test.go:76 +0x158

goroutine 38 [chan receive]:
_/tmp/d20161125-30451-710ita.TestWithConccurentSubscribers.func1(0xc42006a100, 0xc4200543c0, 0xc42007e180, 0xc420054360, 0x12)
	/tmp/d20161125-30451-710ita/solution_test.go:71 +0x104
created by _/tmp/d20161125-30451-710ita.TestWithConccurentSubscribers
	/tmp/d20161125-30451-710ita/solution_test.go:76 +0x158
exit status 2
FAIL	_/tmp/d20161125-30451-710ita	1.005s
--- FAIL: TestMultipleMessagesOneSubscriber (0.00s)
	solution_test.go:105: Expected to recieve NaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNa, but recieved NaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNaNa.
FAIL
exit status 1
FAIL	_/tmp/d20161125-30451-710ita	0.003s
PASS
ok  	_/tmp/d20161125-30451-710ita	0.053s