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

Add TestWorkerPoolSingleQueueMultiDB #44

Merged
merged 6 commits into from
Oct 15, 2024
Merged

Add TestWorkerPoolSingleQueueMultiDB #44

merged 6 commits into from
Oct 15, 2024

Conversation

winebarrel
Copy link
Member

@winebarrel winebarrel commented Oct 13, 2024

同じ名前のqueueを異なるgoroutine・異なるsql.DBで処理しても問題ないことを確認するテストを追加します。

  • 4aff66a サービス用とテスト用でsqlファイルを分けました
  • bf5472f job_test.queueにpidを入れるようにしたので、汎用的なカラム名に変えました
  • cb24401 TestWorkerPoolSingleQueueMultiDB を追加しました
    • おなじ名前のqueueに異なるgoroutine・異なるsql.DBからアクセスしています
    • 各jobにtime.Sleepを入れて、異なるDBセッションで処理されるようにしています
    • pidをvalueカラムにインサートし、value でgroup by することでそれぞれ異なるDBセッションで処理されていることを確認しています
    • もしpg_advisory_lockが効かず、一つのjobを複数回処理してしまった場合、
      • SELECT name, value, COUNT(*) as count FROM job_test GROUP BY name, value の結果が異なる
      • wg.Wait()後にwg.Done()が実行されてpanicになる
      • …などでテストが失敗する想定です
  • 01679bd またやや苦しいのですが、pidが全部異なることで、pool1/poo2それぞれで処理していることを確認するようにしました(それぞれのpoolのworker数が4なので、別のpidになります)
    • 片方止めるとDBコネクションが再利用されてunique countのチェックで失敗します

レビューをお願いします
flakyにはなっていないはず…

Copy link

@kazukousen kazukousen left a comment

Choose a reason for hiding this comment

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

LGTM 🥇

@winebarrel
Copy link
Member Author

🙏

@winebarrel winebarrel merged commit 00beb45 into v4 Oct 15, 2024
1 check passed
@winebarrel winebarrel deleted the add_test branch October 15, 2024 00:30
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

Successfully merging this pull request may close these issues.

2 participants