exercism / go-test-runner

GNU Affero General Public License v3.0
15 stars 17 forks source link

potential BUG: bank-account exercise, timeout issue #111

Open YeungOnion opened 9 months ago

YeungOnion commented 9 months ago

local go version: go1.20.6 linux/amd64 exercise: Bank Account in Go

I may have found an infrastructure bug. My tests timed out on the server, but couldn't find where I was messing up even when comparing to community solutions. I requested mentoring, and bernot-dev replied and mentioned that he thinks it's an issue with infrastructure. We both run it and pass tests locally.

Let me know what other information I may provide.

Unsure if this will give you access, Direct mentoring link to my attempt on this exercise, with source copied below.

my code, copied from iteration 5

package account
import (
    "sync"
)
// Define the Account type here.
type Account struct {
    balance int64
    active  bool
    mu      sync.RWMutex
}
func Open(amount int64) *Account {
    if amount < 0 {
        return nil
    }
    return &Account{
        balance: amount,
        active:  true,
        mu:      sync.RWMutex{},
    }
}
// Balance returns the balance of the account
func (a *Account) Balance() (int64, bool) {
    a.mu.RLock()
    defer a.mu.RUnlock()
    b, ok := a.balance, a.active
    // fail early in lieu of returning invalid state on API
    if b > 0 && !ok {
        panic("an inactive account has nonzero balance")
    } else if b < 0 {
        panic("account found with negative balance")
    }
    return b, ok
}
func (a *Account) Deposit(amount int64) (int64, bool) {
    a.mu.Lock()
    defer a.mu.Unlock()
    b, ok := a.balance, a.active
    if !ok || b+amount < 0 {
        return b, false
    }
    b += amount
    a.balance = b
    return b, true
}
func (a *Account) Close() (int64, bool) {
    a.mu.Lock()
    defer a.mu.Unlock()
    b, ok := a.balance, a.active
    if !ok {
        return 0, false
    }
    a.balance, a.active = 0, false
    return b, true
}
github-actions[bot] commented 9 months ago

Hello. Thanks for opening an issue on Exercism 🙂

At Exercism we use our Community Forum, not GitHub issues, as the primary place for discussion. That allows maintainers and contributors from across Exercism's ecosystem to discuss your problems/ideas/suggestions without them having to subscribe to hundreds of repositories.

This issue will be automatically closed. Please use [this link](https://forum.exercism.org/new-topic?title=potential%20BUG:%20bank-account%20exercise,%20timeout%20issue&body=**local%20go%20version**:%20go1.20.6%20linux/amd64%0D%0A**exercise**:%20%5BBank%20Account%20in%20Go%5D(https://github.com/exercism/go/tree/main/exercises/practice/bank-account)%0D%0A%0D%0AI%20_may_%20have%20found%20an%20infrastructure%20bug.%0D%0AMy%20tests%20timed%20out%20on%20the%20server,%20but%20couldn't%20find%20where%20I%20was%20messing%20up%20even%20when%20comparing%20to%20community%20solutions.%20I%20requested%20mentoring,%20and%20bernot-dev%20replied%20and%20mentioned%20that%20he%20thinks%20it's%20an%20issue%20with%20infrastructure.%20We%20both%20run%20it%20and%20pass%20tests%20locally.%20%0D%0A%0D%0A***Let%20me%20know%20what%20other%20information%20I%20may%20provide.***%0D%0A%0D%0AUnsure%20if%20this%20will%20give%20you%20access,%20%5BDirect%20mentoring%20link%5D(https://exercism.org/mentoring/external_requests/0b4fc9ed7b6440ed9cfcfa63fecc437c)%20to%20my%20attempt%20on%20this%20exercise,%20with%20source%20copied%20below.%0D%0A%0D%0Amy%20code,%20copied%20from%20iteration%205%0D%0A---%0D%0A%0D%0A%60%60%60go%0D%0Apackage%20account%0D%0Aimport%20(%0D%0A%09%22sync%22%0D%0A)%0D%0A//%20Define%20the%20Account%20type%20here.%0D%0Atype%20Account%20struct%20%7B%0D%0A%09balance%20int64%0D%0A%09active%20%20bool%0D%0A%09mu%20%20%20%20%20%20sync.RWMutex%0D%0A%7D%0D%0Afunc%20Open(amount%20int64)%20*Account%20%7B%0D%0A%09if%20amount%20%3C%200%20%7B%0D%0A%09%09return%20nil%0D%0A%09%7D%0D%0A%09return%20&Account%7B%0D%0A%09%09balance:%20amount,%0D%0A%09%09active:%20%20true,%0D%0A%09%09mu:%20%20%20%20%20%20sync.RWMutex%7B%7D,%0D%0A%09%7D%0D%0A%7D%0D%0A//%20Balance%20returns%20the%20balance%20of%20the%20account%0D%0Afunc%20(a%20*Account)%20Balance()%20(int64,%20bool)%20%7B%0D%0A%09a.mu.RLock()%0D%0A%09defer%20a.mu.RUnlock()%0D%0A%09b,%20ok%20:=%20a.balance,%20a.active%0D%0A%09//%20fail%20early%20in%20lieu%20of%20returning%20invalid%20state%20on%20API%0D%0A%09if%20b%20%3E%200%20&&%20!ok%20%7B%0D%0A%09%09panic(%22an%20inactive%20account%20has%20nonzero%20balance%22)%0D%0A%09%7D%20else%20if%20b%20%3C%200%20%7B%0D%0A%09%09panic(%22account%20found%20with%20negative%20balance%22)%0D%0A%09%7D%0D%0A%09return%20b,%20ok%0D%0A%7D%0D%0Afunc%20(a%20*Account)%20Deposit(amount%20int64)%20(int64,%20bool)%20%7B%0D%0A%09a.mu.Lock()%0D%0A%09defer%20a.mu.Unlock()%0D%0A%09b,%20ok%20:=%20a.balance,%20a.active%0D%0A%09if%20!ok%20%7C%7C%20b+amount%20%3C%200%20%7B%0D%0A%09%09return%20b,%20false%0D%0A%09%7D%0D%0A%09b%20+=%20amount%0D%0A%09a.balance%20=%20b%0D%0A%09return%20b,%20true%0D%0A%7D%0D%0Afunc%20(a%20*Account)%20Close()%20(int64,%20bool)%20%7B%0D%0A%09a.mu.Lock()%0D%0A%09defer%20a.mu.Unlock()%0D%0A%09b,%20ok%20:=%20a.balance,%20a.active%0D%0A%09if%20!ok%20%7B%0D%0A%09%09return%200,%20false%0D%0A%09%7D%0D%0A%09a.balance,%20a.active%20=%200,%20false%0D%0A%09return%20b,%20true%0D%0A%7D%0D%0A%60%60%60&category=go ) to copy your GitHub Issue into a new topic on the forum, where we look forward to chatting with you!

If you're interested in learning more about this auto-responder, please read this blog post.

github-actions[bot] commented 9 months ago

Hello. Thanks for opening an issue on Exercism 🙂

At Exercism we use our Community Forum, not GitHub issues, as the primary place for discussion. That allows maintainers and contributors from across Exercism's ecosystem to discuss your problems/ideas/suggestions without them having to subscribe to hundreds of repositories.

This issue will be automatically closed. Please use [this link](https://forum.exercism.org/new-topic?title=potential%20BUG:%20bank-account%20exercise,%20timeout%20issue&body=**local%20go%20version**:%20go1.20.6%20linux/amd64%0D%0A**exercise**:%20%5BBank%20Account%20in%20Go%5D(https://github.com/exercism/go/tree/main/exercises/practice/bank-account)%0D%0A%0D%0AI%20_may_%20have%20found%20an%20infrastructure%20bug.%0D%0AMy%20tests%20timed%20out%20on%20the%20server,%20but%20couldn't%20find%20where%20I%20was%20messing%20up%20even%20when%20comparing%20to%20community%20solutions.%20I%20requested%20mentoring,%20and%20bernot-dev%20replied%20and%20mentioned%20that%20he%20thinks%20it's%20an%20issue%20with%20infrastructure.%20We%20both%20run%20it%20and%20pass%20tests%20locally.%20%0D%0A%0D%0A***Let%20me%20know%20what%20other%20information%20I%20may%20provide.***%0D%0A%0D%0AUnsure%20if%20this%20will%20give%20you%20access,%20%5BDirect%20mentoring%20link%5D(https://exercism.org/mentoring/external_requests/0b4fc9ed7b6440ed9cfcfa63fecc437c)%20to%20my%20attempt%20on%20this%20exercise,%20with%20source%20copied%20below.%0D%0A%0D%0Amy%20code,%20copied%20from%20iteration%205%0D%0A---%0D%0A%0D%0A%60%60%60go%0D%0Apackage%20account%0D%0Aimport%20(%0D%0A%09%22sync%22%0D%0A)%0D%0A//%20Define%20the%20Account%20type%20here.%0D%0Atype%20Account%20struct%20%7B%0D%0A%09balance%20int64%0D%0A%09active%20%20bool%0D%0A%09mu%20%20%20%20%20%20sync.RWMutex%0D%0A%7D%0D%0Afunc%20Open(amount%20int64)%20*Account%20%7B%0D%0A%09if%20amount%20%3C%200%20%7B%0D%0A%09%09return%20nil%0D%0A%09%7D%0D%0A%09return%20&Account%7B%0D%0A%09%09balance:%20amount,%0D%0A%09%09active:%20%20true,%0D%0A%09%09mu:%20%20%20%20%20%20sync.RWMutex%7B%7D,%0D%0A%09%7D%0D%0A%7D%0D%0A//%20Balance%20returns%20the%20balance%20of%20the%20account%0D%0Afunc%20(a%20*Account)%20Balance()%20(int64,%20bool)%20%7B%0D%0A%09a.mu.RLock()%0D%0A%09defer%20a.mu.RUnlock()%0D%0A%09b,%20ok%20:=%20a.balance,%20a.active%0D%0A%09//%20fail%20early%20in%20lieu%20of%20returning%20invalid%20state%20on%20API%0D%0A%09if%20b%20%3E%200%20&&%20!ok%20%7B%0D%0A%09%09panic(%22an%20inactive%20account%20has%20nonzero%20balance%22)%0D%0A%09%7D%20else%20if%20b%20%3C%200%20%7B%0D%0A%09%09panic(%22account%20found%20with%20negative%20balance%22)%0D%0A%09%7D%0D%0A%09return%20b,%20ok%0D%0A%7D%0D%0Afunc%20(a%20*Account)%20Deposit(amount%20int64)%20(int64,%20bool)%20%7B%0D%0A%09a.mu.Lock()%0D%0A%09defer%20a.mu.Unlock()%0D%0A%09b,%20ok%20:=%20a.balance,%20a.active%0D%0A%09if%20!ok%20%7C%7C%20b+amount%20%3C%200%20%7B%0D%0A%09%09return%20b,%20false%0D%0A%09%7D%0D%0A%09b%20+=%20amount%0D%0A%09a.balance%20=%20b%0D%0A%09return%20b,%20true%0D%0A%7D%0D%0Afunc%20(a%20*Account)%20Close()%20(int64,%20bool)%20%7B%0D%0A%09a.mu.Lock()%0D%0A%09defer%20a.mu.Unlock()%0D%0A%09b,%20ok%20:=%20a.balance,%20a.active%0D%0A%09if%20!ok%20%7B%0D%0A%09%09return%200,%20false%0D%0A%09%7D%0D%0A%09a.balance,%20a.active%20=%200,%20false%0D%0A%09return%20b,%20true%0D%0A%7D%0D%0A%60%60%60&category=go ) to copy your GitHub Issue into a new topic on the forum, where we look forward to chatting with you!

If you're interested in learning more about this auto-responder, please read this blog post.

junedev commented 9 months ago

@ErikSchierboom For this exercise, we run Go's built-in race detector. This makes the test run a bit slower but until now we didn't get complains about timeouts. Do you have a way to check whether we started to get more timeouts than usual at some point?

Exercises without the race detector seem to work as fast as usual. I can of course remove the flag for the race detector from the exercise config but it's quite a nice feature to show to students if it kicks in.

ErikSchierboom commented 9 months ago

Do you have a way to check whether we started to get more timeouts than usual at some point?

Not really no, sorry :(