Цветелина обнови решението на 15.11.2014 16:48 (преди над 3 години)
Това ми е първата версия, но исках да имам нещо качено преди крайния срок...
Към профила на Цветелина Борисова
PASS ok _/tmp/d20141204-6466-sf0brw 0.012s PASS ok _/tmp/d20141204-6466-sf0brw 0.016s panic: test timed out goroutine 15 [running]: testing.alarm() /usr/local/lib/go/src/pkg/testing/testing.go:533 +0x44 created by time.goFunc /usr/local/lib/go/src/pkg/time/sleep.go:122 +0x45 goroutine 1 [chan receive]: testing.RunTests(0x8147c74, 0x81c1ba0, 0x19, 0x19, 0x1, ...) /usr/local/lib/go/src/pkg/testing/testing.go:434 +0x69f testing.Main(0x8147c74, 0x81c1ba0, 0x19, 0x19, 0x81c4600, ...) /usr/local/lib/go/src/pkg/testing/testing.go:365 +0x69 main.main() _/tmp/d20141204-6466-sf0brw/_test/_testmain.go:91 +0x81 goroutine 4 [sleep]: time.Sleep(0x3c336080, 0x0) /usr/local/lib/go/src/pkg/runtime/ztime_linux_386.c:19 +0x3a _/tmp/d20141204-6466-sf0brw.TestSizes(0x183611e0) /tmp/d20141204-6466-sf0brw/solution_test.go:111 +0x3a3 testing.tRunner(0x183611e0, 0x81c1bb8) /usr/local/lib/go/src/pkg/testing/testing.go:353 +0x87 created by testing.RunTests /usr/local/lib/go/src/pkg/testing/testing.go:433 +0x684 goroutine 5 [chan receive]: _/tmp/d20141204-6466-sf0brw.func·001(0x18331820, 0x18300308, 0x5, 0x3b9aca00, 0x0, ...) /tmp/d20141204-6466-sf0brw/solution.go:37 +0x45 created by _/tmp/d20141204-6466-sf0brw.(*ExpireMap).Set /tmp/d20141204-6466-sf0brw/solution.go:41 +0x14a goroutine 6 [chan receive]: _/tmp/d20141204-6466-sf0brw.func·001(0x18331820, 0x18300320, 0x5, 0x3b9aca00, 0x0, ...) /tmp/d20141204-6466-sf0brw/solution.go:37 +0x45 created by _/tmp/d20141204-6466-sf0brw.(*ExpireMap).Set /tmp/d20141204-6466-sf0brw/solution.go:41 +0x14a goroutine 7 [chan receive]: _/tmp/d20141204-6466-sf0brw.func·001(0x18331820, 0x18300338, 0x5, 0x3b9aca00, 0x0, ...) /tmp/d20141204-6466-sf0brw/solution.go:37 +0x45 created by _/tmp/d20141204-6466-sf0brw.(*ExpireMap).Set /tmp/d20141204-6466-sf0brw/solution.go:41 +0x14a goroutine 8 [chan receive]: _/tmp/d20141204-6466-sf0brw.func·001(0x18331820, 0x18300350, 0x5, 0x3b9aca00, 0x0, ...) /tmp/d20141204-6466-sf0brw/solution.go:37 +0x45 created by _/tmp/d20141204-6466-sf0brw.(*ExpireMap).Set /tmp/d20141204-6466-sf0brw/solution.go:41 +0x14a goroutine 9 [chan receive]: _/tmp/d20141204-6466-sf0brw.func·001(0x18331820, 0x18300368, 0x5, 0x3b9aca00, 0x0, ...) /tmp/d20141204-6466-sf0brw/solution.go:37 +0x45 created by _/tmp/d20141204-6466-sf0brw.(*ExpireMap).Set /tmp/d20141204-6466-sf0brw/solution.go:41 +0x14a goroutine 10 [chan receive]: _/tmp/d20141204-6466-sf0brw.func·001(0x18331820, 0x18300380, 0x5, 0x3b9aca00, 0x0, ...) /tmp/d20141204-6466-sf0brw/solution.go:37 +0x45 created by _/tmp/d20141204-6466-sf0brw.(*ExpireMap).Set /tmp/d20141204-6466-sf0brw/solution.go:41 +0x14a goroutine 11 [chan receive]: _/tmp/d20141204-6466-sf0brw.func·001(0x18331820, 0x18300398, 0x5, 0x3b9aca00, 0x0, ...) /tmp/d20141204-6466-sf0brw/solution.go:37 +0x45 created by _/tmp/d20141204-6466-sf0brw.(*ExpireMap).Set /tmp/d20141204-6466-sf0brw/solution.go:41 +0x14a goroutine 12 [chan receive]: _/tmp/d20141204-6466-sf0brw.func·001(0x18331820, 0x183003b0, 0x5, 0x3b9aca00, 0x0, ...) /tmp/d20141204-6466-sf0brw/solution.go:37 +0x45 created by _/tmp/d20141204-6466-sf0brw.(*ExpireMap).Set /tmp/d20141204-6466-sf0brw/solution.go:41 +0x14a goroutine 13 [chan receive]: _/tmp/d20141204-6466-sf0brw.func·001(0x18331820, 0x183003c8, 0x5, 0x3b9aca00, 0x0, ...) /tmp/d20141204-6466-sf0brw/solution.go:37 +0x45 created by _/tmp/d20141204-6466-sf0brw.(*ExpireMap).Set /tmp/d20141204-6466-sf0brw/solution.go:41 +0x14a goroutine 14 [chan receive]: _/tmp/d20141204-6466-sf0brw.func·001(0x18331820, 0x183003e0, 0x5, 0x3b9aca00, 0x0, ...) /tmp/d20141204-6466-sf0brw/solution.go:37 +0x45 created by _/tmp/d20141204-6466-sf0brw.(*ExpireMap).Set /tmp/d20141204-6466-sf0brw/solution.go:41 +0x14a exit status 2 FAIL _/tmp/d20141204-6466-sf0brw 1.012s PASS ok _/tmp/d20141204-6466-sf0brw 0.122s PASS ok _/tmp/d20141204-6466-sf0brw 0.175s PASS ok _/tmp/d20141204-6466-sf0brw 0.015s PASS ok _/tmp/d20141204-6466-sf0brw 0.013s --- FAIL: TestSimpleIncrementAndDecrementCalls-2 (0.00 seconds) solution_test.go:276: Incrementing non-number value did not return error solution_test.go:288: Decrementing non-number value did not return error FAIL exit status 1 FAIL _/tmp/d20141204-6466-sf0brw 0.031s PASS ok _/tmp/d20141204-6466-sf0brw 0.014s --- FAIL: TestIncAndDecInManyRoutines-2 (0.01 seconds) solution_test.go:388: Expected 666 but found 599 FAIL exit status 1 FAIL _/tmp/d20141204-6466-sf0brw 0.022s PASS ok _/tmp/d20141204-6466-sf0brw 0.012s PASS ok _/tmp/d20141204-6466-sf0brw 0.012s PASS ok _/tmp/d20141204-6466-sf0brw 0.012s PASS ok _/tmp/d20141204-6466-sf0brw 0.012s PASS ok _/tmp/d20141204-6466-sf0brw 0.112s PASS ok _/tmp/d20141204-6466-sf0brw 0.062s --- FAIL: TestExpiredChanWhenNoOneIsReading-2 (0.06 seconds) solution_test.go:554: Wrong key expired FAIL exit status 1 FAIL _/tmp/d20141204-6466-sf0brw 0.072s --- FAIL: TestExpiredChanDoesNotReturnDeletedKeys-2 (0.05 seconds) solution_test.go:590: Expires chan returned deleted key solution_test.go:594: Expire chan did not return the expected key: long-key FAIL exit status 1 FAIL _/tmp/d20141204-6466-sf0brw 0.062s --- FAIL: TestExpiredChanDoesNotReturnCleanedupKeys-2 (0.05 seconds) solution_test.go:612: Expire chan returned key key after it was cleaned up FAIL exit status 1 FAIL _/tmp/d20141204-6466-sf0brw 0.062s --- FAIL: TestConcurrentOperations-2 (0.08 seconds) solution_test.go:716: Expected something bigger than 1.5e6 but found 14449 FAIL exit status 1 FAIL _/tmp/d20141204-6466-sf0brw 0.096s PASS ok _/tmp/d20141204-6466-sf0brw 0.012s PASS ok _/tmp/d20141204-6466-sf0brw 0.012s PASS ok _/tmp/d20141204-6466-sf0brw 0.012s PASS ok _/tmp/d20141204-6466-sf0brw 0.272s PASS ok _/tmp/d20141204-6466-sf0brw 0.012s
Това ми е първата версия, но исках да имам нещо качено преди крайния срок...
Може ли някой от екипа да ми подскаже дали нещата с затварянето на горутините е ок, защото не съм 100% сигурна :)
Ми при мен се панира, навярно покрай безкрайния цикъл на ред 36 - който не знам защо трябва да е безкраен и да е цикъл ... ползвай select и виж примера в документацията на time.After.
Навярно има и други проблеми, но след тези не виждам смисъл да продължавам да гледам за сега
@Михаил, благодаря :)
Основния проблем в решенето ти е, че обект от този ExpireMap не би могъл да се ползва от различни go-рутини безопасно. Друг малък проблем е, че очакваш винаги някой да чете от канала за изтекли ключове. В условието изрично е казано обратното - не е задължително някой да чете от него. Заради това ти остават висящи рутини.