Skip to content

Conversation

@kush1jpeg
Copy link

@kush1jpeg kush1jpeg commented Oct 3, 2025

Summary

  • Added templates under internal/exercises/templates/:slug

  • Added tests under internal/exercises/templates/:slug

  • Added to internal/exercises/catalog.yaml and provided hints

Fixes #67

Summary by CodeRabbit

  • New Features
    • Added a beginner “WaitGroups” exercise in Projects, focusing on concurrency, sync, goroutines, and waitgroups.
    • Included guided hints on using Add, Done, and Wait to coordinate goroutines.
    • Provided a starter template and a reference solution.
    • Added an accompanying test to verify the expected output (“Worker done”).

@coderabbitai
Copy link

coderabbitai bot commented Oct 3, 2025

Walkthrough

Adds a new WaitGroups exercise: catalog entry with hints, a template implementation and test under templates/39_waitgroup, and a reference solution under solutions/39_waitgroup.

Changes

Cohort / File(s) Summary
Catalog entry
internal/exercises/catalog.yaml
Adds exercise slug 39_waitgroup with title, difficulty, topics, and three hints.
Templates (exercise code and test)
internal/exercises/templates/39_waitgroup/waitgroup.go, internal/exercises/templates/39_waitgroup/waitgroup_test.go
Introduces template code with a goroutine-based worker and a failing test expecting "Worker done". Template intentionally omits proper WaitGroup usage.
Solution implementation
internal/exercises/solutions/39_waitgroup/waitGroup.go
Provides working example using sync.WaitGroup to run worker, call Done, Wait, and return "Worker done".

Sequence Diagram(s)

sequenceDiagram
    participant T as Test (waitgroup_test.go)
    participant F as waitGroup()
    participant WG as sync.WaitGroup
    participant W as worker()

    T->>F: call waitGroup()
    activate F
    F->>WG: Add(1)
    F->>W: start goroutine(worker, &WG, &result)
    note over W: set result = "Worker done"\nWG.Done()
    F->>WG: Wait()
    F-->>T: return result
    deactivate F
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

patch, hacktoberfest, hacktoberfest-accepted, hacktoberfest2025

Suggested reviewers

  • zhravan

Poem

I twitched my nose at goroutines’ run,
A WaitGroup counted—one by one.
Add, then Done, I softly cheer,
Wait for calm, the coast is clear.
“Worker done,” I thump with glee—
Concurrency carrots, served for tea! 🥕🐇

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Out of Scope Changes Check ⚠️ Warning The pull request introduces a solution file under internal/exercises/solutions/39_waitgroup which was not specified in the linked issue’s acceptance criteria that only required templates, tests, catalog entries, and hints. Remove or relocate the solution file to a separate pull request to keep this PR focused solely on adding the exercise templates and tests as scoped in issue #67.
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues Check ✅ Passed The pull request adds the exercise template and accompanying test under internal/exercises/templates/39_waitgroup, updates the exercise catalog with slug 39_waitgroup and helpful hints, thereby satisfying all four acceptance criteria of issue #67.
Title Check ✅ Passed The title succinctly describes the primary change of adding a wait group exercise and aligns directly with the PR’s objective to introduce a WaitGroup tutorial. It is concise and specific enough for a teammate scanning history to understand what was added without extraneous details.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (5)
internal/exercises/catalog.yaml (3)

208-209: Refine topics for discoverability/consistency.

Recommend: ["concurrency", "sync", "goroutines", "waitgroup"].

-  topics: ["waitGroup", "go"]
+  topics: ["concurrency", "sync", "goroutines", "waitgroup"]

210-210: Fix grammar and provide more actionable hints.

Suggested hints:

  • "Use sync.WaitGroup to wait for goroutines."
  • "Call wg.Add(n) before starting n goroutines; each must call wg.Done()."
  • "Call wg.Wait() to block until completion."
-  hints:
-    - "Use Go's waitGroups inorder to wait for the goroutines"
+  hints:
+    - "Use sync.WaitGroup to wait for goroutines."
+    - "Call wg.Add(n) before starting n goroutines; each must call wg.Done()."
+    - "Call wg.Wait() in the parent to block until completion."

205-205: Use lowercase slug for consistency
Change slug: 37_waitGroup to slug: 37_waitgroup.

internal/exercises/solutions/37_waitGroup/waitGroup.go (1)

7-7: Remove stale TODO in solution file.

The functions are implemented; drop the TODO to avoid confusion.

-// TODO: Implement these functions so tests pass
internal/exercises/templates/37_waitGroup/waitGroup_test.go (1)

5-5: Rename test for clarity.

Use a descriptive name.

-func TestHello(t *testing.T) {
+func TestWaitGroup(t *testing.T) {
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ac5de84 and 6a8d46c.

📒 Files selected for processing (4)
  • internal/exercises/catalog.yaml (1 hunks)
  • internal/exercises/solutions/37_waitGroup/waitGroup.go (1 hunks)
  • internal/exercises/templates/37_waitGroup/waitGroup.go (1 hunks)
  • internal/exercises/templates/37_waitGroup/waitGroup_test.go (1 hunks)
🔇 Additional comments (4)
internal/exercises/solutions/37_waitGroup/waitGroup.go (2)

11-14: Correct use of WaitGroup and result handoff.

Goroutine signals Done and writes result; parent waits before return. LGTM.


16-22: Main flow is idiomatic and safe.

Add(1) → start goroutine → Wait() → return result. Good.

internal/exercises/templates/37_waitGroup/waitGroup_test.go (1)

6-9: CI does not run tests; template tests aren’t executed
The workflows only perform formatting, vetting, and building—no go test steps run on PRs, so the template tests won’t break CI.

Likely an incorrect or invalid review comment.

internal/exercises/templates/37_waitGroup/waitGroup.go (1)

9-17: Do not synchronize in the template
The code in internal/exercises/templates/37_waitGroup is intentionally incomplete; tests are meant to fail until students add wg.Add(1), wg.Done(), and wg.Wait().

Likely an incorrect or invalid review comment.

Comment on lines 205 to 209
- slug: 37_waitGroup
title: "WaitGroups"
difficulty: beginner
topics: ["waitGroup", "go"]
hints:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Place “WaitGroups” under concepts, not projects (issue #67 says Concept).

Move this entry to the concepts section to match the issue’s acceptance criteria.

🤖 Prompt for AI Agents
In internal/exercises/catalog.yaml around lines 205 to 209, the "WaitGroups"
exercise is currently listed under projects but should be placed under the
concepts section per issue #67; move the entire exercise entry (slug, title,
difficulty, topics, hints) from the projects list into the concepts list,
preserving its fields and indentation to match surrounding YAML entries, and
remove the original entry from the projects section so there are no duplicates.

@zhravan
Copy link
Owner

zhravan commented Oct 5, 2025

@kush1jpeg: PR LGTM, can you fix the conflicts?

@kush1jpeg
Copy link
Author

@zhravan done.

@zhravan zhravan changed the title Wait grp exercise feat: add wait grp exercise Oct 5, 2025
@zhravan zhravan added the patch Bug fixes and small improvements label Oct 5, 2025
@kaushalyap
Copy link
Collaborator

kaushalyap commented Oct 12, 2025

@kush1jpeg Thank you for the effort, this WaitGroup exercise will go after the channels exercise and before mutexes exercise, because mutexes exercise already use WaitGroup. Can you please do something a bit more meaningful and practical?

Example: File Downloader Solution

func DownloadFiles(urls []string) []string {
	var wg sync.WaitGroup
	results := make([]string, len(urls))

	for i, url := range urls {
		wg.Add(1)
		go func(i int, url string) {
			defer wg.Done()
			time.Sleep(10 * time.Microsecond)
			results[i] = fmt.Sprintf("Downloaded %s", url)
		}(i, url)
	}

	wg.Wait()
	return results
}

I'm okay if you used this exact example.

Also in exercise code have meaningful TODO comments like here

Also make all the exercise, solution, catalog changes a single commit. Or you can squash after reviewing.

@zhravan What do you think?

@zhravan
Copy link
Owner

zhravan commented Oct 12, 2025

@kaushalyap : Commits shouldnt matter, we can squash and merge to main. This should be okay.

Yes let's keep the TODO comments pattern for all exercises, easier for one who use it.

"sync"
)

// TODO: Implement these functions so tests pass
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Give one liner hints if possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

patch Bug fixes and small improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Concept] WaitGroups - add exercise templates

3 participants