Upgrade to Pro — share decks privately, control downloads, hide ads and more …

並行・並列処理のテストは難しい

 並行・並列処理のテストは難しい

B54cc1be9e7ea6e3ff17eaf995fbe35f?s=128

Akihito Nakano

October 27, 2016
Tweet

Transcript

  1. த໺ڿਓ(.01&1"#0JOD ʲϖύϘºϓϨΠυʳ5FDI.FFUVQʙࣗಈςετɾ$*ฤʙ ฒߦɾฒྻॲཧͷςετ͸೉͍͠

  2. 8&#ΞϓϦέʔγϣϯΤϯδχΞ ػೳ։ൃνʔϜ த໺ڿਓ ͖͋ͬʔ !/","/0@"LJIJUP &$ࣄۀ෦Χϥʔϛʔγϣοϓάϧʔϓ IUUQBDLJOUPTIHJUIVCJP

  3. Χϥʔϛʔγϣοϓ

  4. ܅΋ϖύϘͰಇ͔ͳ͍͔ʁ ࠷৽ͷ࠾༻৘ใΛνΣοΫˠ !QC@SFDSVJU

  5. ฒߦɾฒྻॲཧͷςετ

  6. ฒߦɾฒྻॲཧʁ Կʹ͍ͭͯͷൃදͳͷ͔Πϝʔδ͠΍͍͢Α͏ʹ ͸͡Ίʹ໌֬ʹ͓͖ͯ͠·͢ʂ

  7. ฒߦɺฒྻɺඇಉظɺ෼ࢄʜ ϚϧνεϨου Ϛϧνϓϩηε ͪ͜Βʹ͍ͭͯͷൃදͰ͢ ෺ཧతʹಠཱͨ͠ෳ਺ͷϊʔυͰ ฒߦɾฒྻ

  8. ͳͥฒߦɾฒྻॲཧΛςʔϚʹʁ

  9. ฒߦɾฒྻॲཧɹ׆༻ͷྲྀΕ wϓϩηοαߴ଎Խ͔ΒϚϧνίΞ΁ wϦιʔεΛޮ཰తʹ׆༻͢ΔͨΊʹฒߦɾฒྻॲཧ͕஫໨͞ΕΔ wฒߦɾฒྻॲཧ͕ಘҙͳݴޠ͕࿩୊ʹ w3VCZձٞͰ͸(VJME͕ఏҊ͞Εͨ

  10. 1)1

  11. 4OJEFM εφΠσϧ IUUQTHJUIVCDPNBDLJOUPTITOJEFM खܰʹϚϧνϓϩηεͰ͖Δ ࢠϓϩηεͷॲཧ݁ՌΛड͚औΕΔ ϚελʔʗϫʔΧʔϞσϧ 1)1Ҏ্

  12. ϓϧϦΫΤετ׻ܴʂ IUUQTHJUIVCDPNBDLJOUPTITOJEFM

  13. ຊ୊

  14. ฒߦɾฒྻॲཧͷ೉͠͞Λςετͷ؍఺Ͱ

  15. λΠϛϯά໰୊

  16. ϓϩμΫτίʔυ class Foo def run Thread.new do # ৭ʑ @done

    = true end # ৭ʑ end end
  17. ςετίʔυ class FooTest < Test::Unit::TestCase def test_run (foo = Foo.new).run

    sleep 1 assert_true foo.done end end
  18. ςετίʔυ class FooTest < Test::Unit::TestCase def test_run (foo = Foo.new).run

    sleep 1 assert_true foo.done end end ෆ҆ఆ
  19. εςοϓ ॲཧΛ੾Γग़͢

  20. ϓϩμΫτίʔυ͜ΕΛʜ class Foo def run Thread.new do # ৭ʑ @done

    = true end # ৭ʑ end end
  21. ϓϩμΫτίʔυ͜͏ʂ class Foo def run Thread.new do # ৭ʑ @done

    = self.do end # ৭ʑ end def do # ৭ʑ true end end
  22. ςετίʔυ͜ΕΛʜ class FooTest < Test::Unit::TestCase def test_run (foo = Foo.new).run

    sleep 1 assert_true foo.done end end
  23. ςετίʔυ͜͏ʂ class FooTest < Test::Unit::TestCase def test_run (foo = Foo.new).run

    sleep 1 assert_true foo.done end def test_do assert_true Foo.new.do end end
  24. ඇಉظͳ෦෼Λ ಉظॲཧͱͯ͠ςετͰ͖ΔΑ͏ʹͳͬͨʂ

  25. )VNCMF0CKFDUύλʔϯ Y6OJU5FTU1BUUFSOT$I

  26. ͕͔ͩ͠͠

  27. ςετίʔυ·ͩ໰୊͸ղܾ͍ͯ͠ͳ͍ʜ class FooTest < Test::Unit::TestCase def test_run (foo = Foo.new).run

    sleep 1 assert_true foo.done end def test_do assert_true Foo.new.do end end ෆ҆ఆ
  28. εςοϓ ϝοηʔδύογϯάΛ࢖͏

  29. lϝϞϦͷ্ͰγΣΞ͢ΔͷͰ͸ͳ͘ ίϛϡχέʔγϣϯͰγΣΞ͢Δz 4J[FE2VFVFΛ࢖ͬͯ ͦΕͬΆ͍͜ͱΛ΍Γ·͢

  30. ϓϩμΫτίʔυ͜ΕΛʜ class Foo def run Thread.new do # ৭ʑ @done

    = self.do end # ৭ʑ end def do # ৭ʑ true end end
  31. ϓϩμΫτίʔυ͜͏ʂ class Foo def initialize @done = SizedQueue.new(1) end def

    run Thread.new do # ৭ʑ @done << self.do end # ৭ʑ end … (ུ) … end
  32. ςετίʔυ͜ΕΛʜ class FooTest < Test::Unit::TestCase def test_run (foo = Foo.new).run

    sleep 1 assert_true foo.done end def test_do assert_true Foo.new.do end end
  33. ςετίʔυ͜͏ʂ class FooTest < Test::Unit::TestCase def test_run (foo = Foo.new).run

    assert_true foo.done.pop end def test_do assert_true Foo.new.do end end
  34. λΠϛϯά໰୊ ղܾʂ

  35. ଞʹ΋ w ౰εϥΠυͰ͸൚༻తͳςΫχοΫͷ͝঺հͰ͕ͨ͠ w ݴޠ΍ϑϨʔϜϫʔΫ͕ఏڙ͢Δศརػೳ΋͋Γ·͢ w ྫ(Pݴޠͷ3BDF%FUFDUPS

  36. ·ͱΊ

  37. ·ͱΊ w ฒߦɾฒྻॲཧͷ೉͠͞ʹ΋ςετͰର߅Ͱ͖Δ w ಛ༗ͷϓϥΫςΟε͕͋Δ w ஌ݟΛڞ༗͍͖ͯ͠·͠ΐ͏ʂʂ̍