Skip to content

Commit e9216b4

Browse files
Victor Rudometovshipilev
authored andcommitted
8178698: javax/sound/midi/Sequencer/MetaCallback.java failed with timeout
Backport-of: 43ce047f9f417a1d8afa83a3d2c2429a478975db
1 parent a9cf1e3 commit e9216b4

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

test/jdk/ProblemList.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,6 @@ javax/sound/sampled/Clip/Drain/ClipDrain.java 7062792 generic-all
685685
javax/sound/sampled/Mixers/DisabledAssertionCrash.java 7067310 generic-all
686686

687687
javax/sound/midi/Sequencer/Recording.java 8167580,8265485 linux-all,macosx-aarch64
688-
javax/sound/midi/Sequencer/MetaCallback.java 8178698 linux-all
689688
javax/sound/midi/Sequencer/Looping.java 8136897 generic-all
690689

691690
############################################################################

test/jdk/javax/sound/midi/Sequencer/MetaCallback.java

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -31,13 +31,16 @@
3131
import javax.sound.midi.Sequencer;
3232
import javax.sound.midi.ShortMessage;
3333
import javax.sound.midi.Track;
34+
import java.util.ArrayList;
35+
import java.util.Collections;
36+
import java.util.List;
3437

3538
/**
3639
* @test
3740
* @bug 4347135
3841
* @summary MIDI MetaMessage callback inconsistent
3942
* @key intermittent sound
40-
* @run main/othervm MetaCallback
43+
* @run main/othervm/timeout=120 MetaCallback
4144
*/
4245
public class MetaCallback implements MetaEventListener {
4346

@@ -59,11 +62,15 @@ static ShortMessage MidiMsg3(int a, int b, int c) {
5962

6063
public static int TOTAL_COUNT = 100;
6164

62-
int metaCount = 0;
63-
boolean finished = false;
65+
volatile int metaCount = 0;
66+
volatile boolean finished = false;
67+
// On M1 Mac sometimes system notifies listener about the same message twice
68+
static List<MetaMessage> received = Collections.synchronizedList(new ArrayList<>());
69+
long startTimeMs;
6470

6571
MetaCallback() throws Exception {
6672

73+
startTimeMs = System.currentTimeMillis();
6774
sequencer=MidiSystem.getSequencer();
6875
sequence=new Sequence(Sequence.PPQ,240);
6976
track=sequence.createTrack();
@@ -101,13 +108,28 @@ static ShortMessage MidiMsg3(int a, int b, int c) {
101108
}
102109
}
103110
void start() {sequencer.start();}
104-
void stop() {sequencer.stop();}
111+
void stop() {
112+
sequencer.stop();
113+
sequencer.close();
114+
}
105115

106116
public void meta(MetaMessage msg) {
107117
System.out.println(""+metaCount+": got "+msg);
108118
if (msg.getType() == 0x2F) {
109119
finished = true;
110120
} else if (msg.getData().length > 0 && msg.getType() == 1) {
121+
if (!received.contains(msg)) {
122+
received.add(msg);
123+
} else {
124+
// Add some additional debug output for the case of duplicate meta message
125+
// The test will fail anyway at the end
126+
System.out.println("Duplicate message received after getting "
127+
+ received.size() + " messages.");
128+
System.out.println("Sequencer in use: " + sequencer);
129+
System.out.println("Time from test start: " +
130+
(System.currentTimeMillis() - startTimeMs) + "ms");
131+
Thread.dumpStack();
132+
}
111133
metaCount++;
112134
}
113135
}

0 commit comments

Comments
 (0)