Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
YeungOnion opened this issue Nov 21, 2023 · 4 comments
Open

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

YeungOnion opened this issue Nov 21, 2023 · 4 comments

Comments

@YeungOnion
Copy link

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
}
Copy link

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 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 junedev reopened this Nov 23, 2023
@junedev junedev transferred this issue from exercism/go Nov 23, 2023
Copy link

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 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
Copy link
Member

junedev commented Nov 23, 2023

@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.

@junedev junedev reopened this Nov 23, 2023
@ErikSchierboom
Copy link
Member

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

Not really no, sorry :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants