Skip to content
This repository
Browse code

test: remove consumer_producer test

It fails intermittently on Travis for no other reason than that Travis
is occasionally slow. Reduce the number of false positives, remove the
test.
  • Loading branch information...
commit 1f52fc1c5a3961329530810327c7f69f6e022c8a 1 parent 2f55353
Ben Noordhuis authored January 06, 2013
138  test/test-condvar-consumer-producer.c
... ...
@@ -1,138 +0,0 @@
1  
-/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
2  
- *
3  
- * Permission is hereby granted, free of charge, to any person obtaining a copy
4  
- * of this software and associated documentation files (the "Software"), to
5  
- * deal in the Software without restriction, including without limitation the
6  
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7  
- * sell copies of the Software, and to permit persons to whom the Software is
8  
- * furnished to do so, subject to the following conditions:
9  
- *
10  
- * The above copyright notice and this permission notice shall be included in
11  
- * all copies or substantial portions of the Software.
12  
- *
13  
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14  
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16  
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17  
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18  
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19  
- * IN THE SOFTWARE.
20  
- */
21  
-
22  
-#include "uv.h"
23  
-#include "task.h"
24  
-
25  
-#include <stdio.h>
26  
-#include <stdlib.h>
27  
-
28  
-#define MAX_CONSUMERS 32
29  
-#define MAX_LOOPS 1000
30  
-
31  
-struct buffer_s {
32  
-  ngx_queue_t queue;
33  
-  int data;
34  
-};
35  
-typedef struct buffer_s buffer_t;
36  
-
37  
-static ngx_queue_t queue;
38  
-static uv_mutex_t mutex;
39  
-static uv_cond_t empty;
40  
-static uv_cond_t full;
41  
-
42  
-static volatile int finished_consumers = 0;
43  
-
44  
-
45  
-static void produce(int value) {
46  
-  buffer_t* buf;
47  
-
48  
-  buf = malloc(sizeof(*buf));
49  
-  ngx_queue_init(&buf->queue);
50  
-  buf->data = value;
51  
-  ngx_queue_insert_tail(&queue, &buf->queue);
52  
-}
53  
-
54  
-
55  
-static int consume(void) {
56  
-  ngx_queue_t* q;
57  
-  buffer_t* buf;
58  
-  int data;
59  
-
60  
-  ASSERT(!ngx_queue_empty(&queue));
61  
-  q = ngx_queue_last(&queue);
62  
-  ngx_queue_remove(q);
63  
-
64  
-  buf = ngx_queue_data(q, buffer_t, queue);
65  
-  data = buf->data;
66  
-  free(buf);
67  
-
68  
-  return data;
69  
-}
70  
-
71  
-
72  
-static void producer(void* arg) {
73  
-  int i;
74  
-
75  
-  (void) arg;
76  
-
77  
-  for (i = 0; i < MAX_LOOPS * MAX_CONSUMERS; i++) {
78  
-    uv_mutex_lock(&mutex);
79  
-    while(!ngx_queue_empty(&queue))
80  
-      uv_cond_wait(&empty, &mutex);
81  
-    produce(i);
82  
-    uv_cond_signal(&full);
83  
-    uv_mutex_unlock(&mutex);
84  
-  }
85  
-}
86  
-
87  
-
88  
-static void consumer(void* arg) {
89  
-  int i;
90  
-  int value;
91  
-
92  
-  (void) arg;
93  
-
94  
-  for (i = 0; i < MAX_LOOPS; i++) {
95  
-    uv_mutex_lock(&mutex);
96  
-    while (ngx_queue_empty(&queue))
97  
-      uv_cond_wait(&full, &mutex);
98  
-    value = consume();
99  
-    ASSERT(value < MAX_LOOPS * MAX_CONSUMERS);
100  
-    uv_cond_signal(&empty);
101  
-    uv_mutex_unlock(&mutex);
102  
-  }
103  
-
104  
-  finished_consumers++;
105  
-}
106  
-
107  
-
108  
-TEST_IMPL(consumer_producer) {
109  
-  int i;
110  
-  uv_thread_t cthreads[MAX_CONSUMERS];
111  
-  uv_thread_t pthread;
112  
-
113  
-  ngx_queue_init(&queue);
114  
-  ASSERT(0 == uv_mutex_init(&mutex));
115  
-  ASSERT(0 == uv_cond_init(&empty));
116  
-  ASSERT(0 == uv_cond_init(&full));
117  
-
118  
-  for (i = 0; i < MAX_CONSUMERS; i++) {
119  
-    ASSERT(0 == uv_thread_create(&cthreads[i], consumer, NULL));
120  
-  }
121  
-
122  
-  ASSERT(0 == uv_thread_create(&pthread, producer, NULL));
123  
-
124  
-  for (i = 0; i < MAX_CONSUMERS; i++) {
125  
-    ASSERT(0 == uv_thread_join(&cthreads[i]));
126  
-  }
127  
-
128  
-  ASSERT(0 == uv_thread_join(&pthread));
129  
-
130  
-  LOGF("finished_consumers: %d\n", finished_consumers);
131  
-  ASSERT(finished_consumers == MAX_CONSUMERS);
132  
-
133  
-  uv_cond_destroy(&empty);
134  
-  uv_cond_destroy(&full);
135  
-  uv_mutex_destroy(&mutex);
136  
-
137  
-  return 0;
138  
-}
2  test/test-list.h
@@ -31,7 +31,6 @@ TEST_DECLARE   (condvar_2)
31 31
 TEST_DECLARE   (condvar_3)
32 32
 TEST_DECLARE   (condvar_4)
33 33
 TEST_DECLARE   (condvar_5)
34  
-TEST_DECLARE   (consumer_producer)
35 34
 TEST_DECLARE   (semaphore_1)
36 35
 TEST_DECLARE   (semaphore_2)
37 36
 TEST_DECLARE   (semaphore_3)
@@ -238,7 +237,6 @@ TASK_LIST_START
238 237
   TEST_ENTRY  (condvar_3)
239 238
   TEST_ENTRY  (condvar_4)
240 239
   TEST_ENTRY  (condvar_5)
241  
-  TEST_ENTRY  (consumer_producer)
242 240
   TEST_ENTRY  (semaphore_1)
243 241
   TEST_ENTRY  (semaphore_2)
244 242
   TEST_ENTRY  (semaphore_3)
1  uv.gyp
@@ -314,7 +314,6 @@
314 314
         'test/test-thread.c',
315 315
         'test/test-barrier.c',
316 316
         'test/test-condvar.c',
317  
-        'test/test-condvar-consumer-producer.c',
318 317
         'test/test-timer-again.c',
319 318
         'test/test-timer.c',
320 319
         'test/test-tty.c',

2 notes on commit 1f52fc1

Shigeki Ohtsu

Timeout errors seemed to be occurred on Travis. Probably, 32 threads x 1000 loops are too heavy to be completed on it.
No problems if this test is removed.

Ben Noordhuis

Yeah. I liked the test but it made the test suite fail too often.

Please sign in to comment.
Something went wrong with that request. Please try again.